“Nobody thought this was going to happen,” President Trump said at a cabinet meeting on Wednesday. “And I appreciate Kim Jong-un for doing this and allowing them to go.”

WASHINGTON — The release of three American prisoners cleared away a last obstacle on Wednesday to a landmark nuclear summit meeting between President Trump and North Korea’s leader, Kim Jong-un.

North Korea freed the prisoners, all Americans of Korean descent, even as the two countries finalized details for a meeting between their leaders. The move was North Korea’s most tangible gesture aimed at improving relations with the United States since Mr. Trump took office.

The resolution of the prisoner standoff hardly guaranteed success at the meeting, which will grapple with the far more complicated issues of North Korea’s nuclear arsenal, divisions on the peninsula and security in Asia. But American officials said it sent another signal that North Korea may be serious about ending its long confrontation with the United States and its allies after nearly seven decades of mutual antagonism.

Mr. Trump exulted over the release and publicly entertained talk that he could even win a Nobel Peace Prize for his diplomacy. He was so eager to associate himself with the freed prisoners that he decided to personally travel to Joint Base Andrews outside Washington in the middle of the night to welcome them back to the United States, something other presidents have not typically done in similar circumstances.

“Nobody thought this was going to happen, and if it did, it would be years or decades, frankly,” Mr. Trump said at the White House shortly after they were released. “Nobody thought this was going to happen. And I appreciate Kim Jong-un for doing this and allowing them to go.”

The three were handed over to Secretary of State Mike Pompeo, who made a second visit to Pyongyang, the North’s capital, to lock down details of the upcoming meeting between the president and Mr. Kim. Mr. Trump said it would not be held in the Demilitarized Zone between North and South Korea, as he had earlier suggested, and speculation centered on Singapore, a neutral site that has better facilities and is close to North Korea.

The United States has persistently demanded the release of its three citizens — Kim Dong-chul, Tony Kim and Kim Hak-song — who have all been held on charges of committing espionage or unidentified “hostile acts” against North Korea. Two of them were arrested after Mr. Trump took office last year.

“For Trump, the release validates his view that only he can effectively negotiate with North Korea,” said Evan S. Medeiros, a former senior Asia adviser to President Barack Obama. “For Kim, it helps him undermine the maximum pressure campaign, which has probably peaked, and drives up the price and lengthens the timeline for denuclearization.”

The three freed prisoners issued a statement as they made their way to Washington. “We would like to express our deep appreciation to the United States government, President Trump, Secretary Pompeo and the people of the United States for bringing us home,” they said. “We thank God, and all our families and friends who prayed for us and for our return. God bless America, the greatest nation in the world.”

In the first comments attributed to Kim Jong-un confirming the planned meeting, the North Korean news agency said he expressed thanks to Mr. Trump for showing “deep interest in settling the issue through dialogue” and said the session would be an “excellent first step toward promotion of the positive situation development in the Korean Peninsula.”

During his one-day trip to Pyongyang, Mr. Pompeo and senior North Korean officials exchanged optimistic words about the future of the relationship.

At a lunch of poached fish and duck and red wine, on the 39th floor of the Koryo Hotel, Kim Yong-chol,…