North Korean ruler Kim Jong-un has been photographed smiling and laughing with Secretary of State Mike Pompeo just moments before three American detainees boarded a flight home from Pyongyang after months in captivity.

The plane carrying Pompeo and the three Americans - Kim Dong Chul, Kim Hak Song and Tony Kim - touched down on US soil in Anchorage, Alaska on Wednesday for a brief refueling stop before continuing on its journey to Washington, DC.

President Donald Trump tweeted late Wednesday that he was 'Looking forward to greeting the Hostages (no longer) at 2:00 A.M.'

'President Trump appreciates leader Kim Jong Un’s action to release these American citizens, and views this as a positive gesture of goodwill,' the White House said in a statement.

After months of anticipation and drama, the release of three American detainees by North Korea played out amid high-stakes diplomacy and was only sealed about an hour before Pompeo was wheels-up from Pyongyang.

North Korean ruler Kim Jong-un has been photographed smiling and laughing with Secretary of State Mike Pompeo just moments before three American detainees boarded a flight home after months in captivity

Photographs of Kim and Pompeo shaking hands were released by the North Korean government on Wednesday

In a major diplomatic coup for the Trump administration, Pompeo managed to secure the release of three Americans detained by the North Korean government

It was the culmination of Pompeo's 12-and-a-half-hour visit to the North Korean capital, which included a 90-minute meeting with Kim

The three men walked on their own from a van and onto Pompeo's plane.

It was the culmination of Pompeo's 12-and-a-half-hour visit to the North Korean capital, which included a 90-minute meeting with Kim.

Returning to his hotel from that meeting, Pompeo had given reporters a fingers-crossed sign when asked if there was good news about the detainees.

A North Korean official came to the hotel shortly after to inform Pompeo that Kim had granted amnesties to the three and that they would be released at 7pm local time, according to a senior US official present for the exchange.

Carl Risch, the assistant secretary of state for consular affairs, and a doctor went to another hotel to pick up the men and bring them to the airport, the official said.

They finally left custody at 7:45pm, and by 8:42pm they were flying home.

As soon as the plane cleared North Korean airspace, Pompeo called Trump to inform him of the releases with the men all apparently in good health; then other officials notified their families.

'They all walked up the stairs themselves, with their own power, so good enough to do that,' Pompeo told USA Today.

Even before Pompeo's plane had touched down for a stopover at Yokota Air Base in neighboring Japan, the president announced to the world by Twitter that the '3 wonderful gentlemen' were free.

The plane carrying Pompeo and the three Americans - Kim Dong Chul, Kim Hak Song and Tony Kim - touched down on US soil in Anchorage, Alaska on Wednesday for a brief refueling stop before continuing on its journey to Washington, DC

Earlier on Wednesday, the US government plane on which Pompeo and the three newly freed men were traveling (left) landed at Yokota U.S. Airbase in the outskirts of Tokyo before refueling for the long haul back to North America

Two fire trucks are hoisting up a large American flag which will greet the freed detainees once they arrive at Joint Base Andrews sometime around 2:00am Eastern Standard Time

President Donald Trump tweeted late Wednesday that he was 'Looking forward to greeting the Hostages (no longer) at 2:00 A.M.'

In a statement released by the State Department, the former detainees expressed their 'deep appreciation' to the US government, Trump, Pompeo and the American people 'for bringing us home.'

They are the latest in a series of Americans to be held in North Korea for alleged anti-state activities in recent years, only to be freed during the visit of a high-level US official or statesman.

Their releases draw a line under an issue that had weighed on plans for a historic summit between Kim and Trump that will focus on North Korea's nuclear weapons.

'We're granting amnesty to the three detained Americans,' the North Korean emissary told Pompeo at Pyongyang's Koryo Hotel, according to the senior US official who requested anonymity to discuss the exchange.

'We issued the order to grant immediate amnesty to the detainees.'

'That's great,' the secretary of state replied.

The North Korean official then advised that the releases would follow a 'very brief ceremony' - which he described as more like a legal process.

The official closed with a gentle warning for the U.S. to prevent a repeat: 'You should make care that they do not make the same mistakes again,' the official said.

'This was a hard decision.'

U.S. citizen Kim Hak-song was detained 'on suspicion of acts against the state'

Kim Dong-chul, pictured above, left and right, had been detained since 2015. He was arrested for spying and had been sentenced to 10 years' hard labor

North Korea's official news agency, KCNA, said early Thursday that Kim 'accepted an official suggestion of the US president for the release of Americans who have been detained in the DPRK for their anti-DPRK hostilities,' referring to the initials of the authoritarian nation's official name, the Democratic People's Republic of Korea.

The dispatch also made the first official mention by the North of plans for the Trump-Kim summit.

The Trump administration has made clear it regarded the arrests as politically motivated, and had been bitterly critical of North Korea's refusal to grant consular access to the three, other than a brief visit by a US envoy last June.

Tony Kim, also known as Kim Sang-Duk, was a Korean-American professor and aid worker before his arrest

The envoy had repatriated college student Otto Warmbier, who was sentenced to 15 years in prison with hard labor for stealing a propaganda poster.

Warmbier died in June 2017, days after he arrived back in the US with severe brain damage.

Since then, pressure to win the releases of the other three men, whom the administration has referred to as 'hostages,' has intensified.

Relatively little is known about the men, all Korean-Americans, and the circumstances in which they ended up in North Korean custody.

Kim Dong Chul, a former Virginia resident who had reportedly run a company on North Korea's border with Russia, had been sentenced in April 2016 to 10 years in prison with hard labor after being convicted of espionage.

Kim Hak Song and Tony Kim, who had both taught at a university in Pyongyang that was founded with donations from Christian groups, had been held for about one year and apparently had not been tried.

President Trump triumphantly announced the release of the trio of Americans in his own style – with a pair of tweets

Tony Kim's son Sol Kim, a graduate student in California, is the only relative of the detainees to have appealed in public for their freedom.

On learning of the release of Tony, who also uses the name Kim Sang-duk, his family expressed gratitude and credited Trump for engaging directly with North Korea.

'We ... want to thank the President for engaging directly with N. Korea. Mostly, we thank God for Tony’s safe return,' they said.

On learning of the release of Tony, who also uses the name Kim Sang-duk, his family expressed gratitude and credited Trump for engaging directly with North Korea

The family also called for prayers for 'the people of North Korea and for the release of all who are still being held.'

Washington and Pyongyang have remained in a state of war since the fighting in the 1950-53 Korean War ended and do not have formal diplomatic ties, complicating efforts to handle the cases of American detainees.

Typically, Swedish diplomats based in North Korea handle US consular affairs.

Pompeo, the most senior US official to meet with a North Korean leader since 2000, was making his second visit to the isolated nation in five weeks - and less than two weeks after becoming top diplomat.

Before Wednesday, the only American released by North Korea during Trump’s presidency had been Otto Warmbier (above), a 22-year-old university student who returned to the US in a coma last summer after 17 months of captivity and died days later

Some in Washington had expressed disappointment that Pompeo's first trip, made in secret when he was still CIA director, did not win the freedom of the three captives.

Pompeo said Wednesday he was 'thrilled' the men were now out.

'Though we're not quite back home yet, I welcomed them back,' he said, recounting his first words with the men after they were freed.

'They were happy to be with us on this plane to be sure,' he said.

The three boarded under their own steam, when most of the US delegation had already got on the plane.

They were seated with medical personnel in a curtained off area of the aircraft.

After arriving at the stop in Japan, the men transferred to another plane with more medical facilities and were expected to land at Joint Base Andrews outside Washington in the wee hours of Thursday, where Trump planned to greet them.