SEOUL, South Korea — President Donald Trump scored a diplomatic victory Wednesday as North Korea freed three imprisoned U.S. citizens to return to the United States with Secretary of State Mike Pompeo, a goodwill gesture from the North’s dictator, Kim Jong Un, ahead of his summit with the president.

Trump announced the men’s freedom on Twitter early Wednesday, and two reporters traveling with Pompeo later saw the three Korean-American men boarding the secretary’s plane without assistance as he was set to return to Washington. Trump said he and Vice President Mike Pence would meet the plane at 2 a.m. at Joint Base Andrews.

“I am pleased to inform you that Secretary of State Mike Pompeo is in the air and on his way back from North Korea with the 3 wonderful gentlemen that everyone is looking so forward to meeting,” Trump tweeted.

Later, talking briefly to reporters before a Cabinet meeting, Trump thanked Kim in language that was unimaginable just months ago, as the two exchanged threats of nuclear annihilation. “I appreciate Kim Jong Un doing this and allowing them to go,” Trump said.

The president also credited the leaders of China, Japan and South Korea for their help in nudging the North Korean leader, and Trump indulged in some self-congratulation as well. Asked if he thought he personally deserved a Nobel Peace Prize, Trump replied, “Everyone thinks so but I would never say it.”

Later Wednesday, The Associated Press reported that the men’s plane had touched down on American soil in Alaska for a refueling stop, and the State Department released a statement.

“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.”

The administration was eager to win the men’s release to provide good diplomatic news to offset the international opprobrium after Trump on Tuesday withdrew the United States from the 2015 multinational nuclear agreement with Iran. Last week the president had tweeted that the three men’s freedom was “imminent.”

Despite the gesture from Kim, Trump acknowledged that his meeting with the North Korean leader _ the first between a sitting American president and a leader of the long-isolated country _ could still be “scuttled.” The U.S. is demanding that North Korea unilaterally give up its nuclear arsenal and building program, something Kim is widely expected to resist.

“Everything can be scuttled,” Trump said.

“People never thought you were going to have a situation where we’re having serious and positive communication with North Korea, and we are,” he added. “What happens? Who knows? We have a chance at something really great for the world.”

Kim’s overture on the prisoners, two of whom were detained last year and one late in President Barack Obama’s tenure, came after he and Pompeo met for 90 minutes in Pyongyang, the North Korean capital, to finish plans for Kim’s meeting with Trump. Trump told reporters that the two sides had agreed to a place and time. It would not be held in the demilitarized zone separating North and South Korea, he said; Trump previously has mentioned Singapore, the Southeast Asian island state, as a possible venue.

Pompeo’s short trip _ his second visit to Pyongyang in just over a month _ came a day after Kim traveled by plane to northeast China to confer with President Xi Jinping of China, North Korea’s closest ally and protector. It was Kim’s second meeting with Xi in recent months as China has sought to exert its influence over its client state.

The administration had faced questions for weeks about whether it would demand that the imprisoned men be freed as a precondition for the summit.

The three citizens are Kim Dong-chul, a businessman arrested in 2015 and serving 10 years on espionage charges; and Kim Sang-duk and Kim Hak-song, professors associated with Pyongyang University of Science and Technology who were captured last year. Kim Sang-duk, who also goes by Tony Kim, graduated from the University of California, Riverside with a master’s degree in 1990.

Trump and Pompeo said the men appeared to be in good health. “Doctors are with them now,” Pompeo told the two reporters aboard his plane once it took off. “All indications are that their health is as good as could be, given what they have been through.”

Their release comes just under a year after the death of Otto Warmbier, an American college student detained on theft charges in Pyongyang in 2016. The North released Warmbier in a coma, and he died a week after returning to the United States.

His father, Fred Warmbier, sought to remind the world about the case amid the diplomatic glow celebrating North and South Koreas’ seeming rapprochement during the recent Winter Olympics held in the South. He traveled in February to the games’ site in Pyeongchang, South Korea, and attended the opening ceremony to highlight North Korea’s record of human rights abuses.

For Pompeo, just two weeks into his job as the nation’s top diplomat, the release of the three men _ together with planning what could be a historic summit meeting _ has made for a heady start. His previous visit with Kim was over Easter weekend, when Pompeo was still CIA director, awaiting Senate confirmation to become secretary of state.

The release was not without last-minute drama.

After his 90-minute discussion with Kim, Pompeo returned to his hotel, and when reporters asked if there was good news on the detainees, he crossed his fingers.

A North Korean official later sought out Pompeo at his hotel and informed him that Kim had granted the men “amnesty,” according to an account from a senior U.S. official present for the exchange.

“We’re granting amnesty to the three detained Americans,” the North Korean emissary told Pompeo. “We issued the order to grant immediate amnesty to the detainees.”

“That’s great,” Pompeo said.

“It should be a very brief ceremony,” the North Korean continued, referring to something of a legal process. He added in closing, “You should make care that they do not make the same mistakes again. This was a hard decision.”

The emissary told Pompeo the men would be released at 7 p.m. local time. Carl Risch, the assistant secretary of state for consular affairs, and a doctor then went to another hotel to pick the men up and accompanied them to the airport.

Forty minutes after leaving the hotel, they arrived at the airport at 8:25 p.m. local time. The former prisoners were in the air with Pompeo, headed for the U.S., less than an hour after leaving custody.

All three men were accused by Pyongyang of subversion and “anti-state” activities. That is a catchall phrase the North Koreans use to incarcerate people, often foreigners, for a range of supposed crimes, big and small.

Yoon Young-chan, a spokesman for South Korean President Moon Jae-in, welcomed the North’s action as a positive step toward a successful summit between Kim and Trump.

He also noted that the North’s decision to release the three ethnic Koreans could signal that Pyongyang might release six South Koreans detained there, as Moon recently requested during a summit with Kim. South Korean officials expressed hope that the United States would help.

According to the reporters with Pompeo, he also met with Kim Yong Chol, the North’s former military intelligence chief, and Ri Su Yong, its former foreign minister, on Wednesday.

Alex Gladstein, the chief strategy officer at the Human Rights Foundation, said, “As an American, I’m thrilled that these people are coming home to their families.”

Yet Gladstein, who works with North Korean defectors, hoped the release wouldn’t distract from the documented evidence of the state’s continuing human rights abuses against its people, including forced labor camps, torture and political executions on mass scales.

“The government is at war with them every day,” he said of the North Korean people. Yet, Gladstein added, North Korea’s threat to South Korea and other countries is “the war that people are excited to end.”

Although uncertainty _ even skepticism _ about the summit and its outcome persist, the diplomatic developments in recent months since North Korea accepted the South’s Olympics invitation have been striking to many experts.

The North provocatively had launched dozens of ballistic missiles and conducted three underground nuclear tests in recent years _ all violations of international norms _ to build its weapons program.

Last year, North Korea launched three missiles into space that showed it could strike the United States mainland, provoking an international crisis and new rounds of economic sanctions from the United Nations.

Kim proclaimed on New Year’s Day that his nation had achieved a national nuclear force that could counter any aggression by the United States, its main security concern. He also noted his desire to have his country participate in the Olympics, signaling the months of subsequent diplomacy that led to the current warming.