The last two Americans being held prisoner by North Korea have been released and allowed to return home after an extraordinary trip to that isolated nation’s capital by the United States’ top intelligence official, U.S. officials said Saturday.

Matthew Miller and Kenneth Bae, both serving multi-year sentences in North Korean labor camps, arrived at Joint Base Lewis-McChord in Washington state shortly after 9 p.m. local time Saturday accompanied by Director of National Intelligence James R. Clapper.

At a news conference a short time after landing at the base south of Seattle, Bae thanked President Obama and also the North Korean government for releasing him, the Associated Press reported. “It’s been an amazing two years, I learned a lot,” Bae said.

Members of Bae’s family, who live near the sprawling military base south of Seattle, met him when he landed, the AP said. His mother hugged him after he got off the plane. Miller stepped off the U.S. government aircraft a short time later and was also greeted with hugs.

Brian Hale, a spokesman for Clapper’s office, said in a written statement earlier Saturday that, “We can confirm that [Bae and Miller] have been allowed to depart the DPRK and are on their way home,” using the initials for North Korea. Hale declined to offer any additional details on the terms of the Americans’ release or Clapper’s role in the mission to retrieve them.

President Obama says the United States is grateful for the safe return of the two Americans Matthew Miller and Kenneth Bae, who were being held in North Korea. (Reuters)

President Obama applauded the action, telling reporters at the White House: “It’s a wonderful day for them and their families. We’re grateful for their safe return.” He also thanked Clapper for his unusual role in negotiating the prisoners’ freedom, saying it “was obviously a challenging mission.”

Bae’s sister, Terri Chung, posted a note Saturday on a Web site devoted to her brother’s release: “I am thrilled to imagine hugging my brother soon. ... He can now recover from this imprisonment and look forward to his wife, kids and rest of his life. Our Thanksgiving celebration this year will be one we will never forget.”

The surprise release is in many ways the latest bewildering move by North Korea, a nuclear-armed country that is among the most insular in the world and a long-standing adversary of the United States.

But there have been some recent indications that the men’s departure was possible. North Korean leader Kim Jong Un has seemed increasingly eager to get rid of the prisoners amid growing scrutiny of his country’s human rights record by the United Nations, a process that in theory could lead to indictments of him and other senior officials in the International Criminal Court.

Kim, 31, had recently made the two prisoners available for highly controlled interviews with visiting journalists, exchanges in which the men asked for help to be released. His government had also made clear that it wanted a high-ranking U.S. official to travel to Pyongyang to secure the Americans’ freedom — a visit that could be seen as enhancing North Korea’s prestige as well as providing an opportunity to discuss broader issues with a senior official in the Obama administration.

The U.N. inquiry “has clearly gotten under the North Korean skin,” said Scott Snyder, an expert on the country at the Council on Foreign Relations. “It suggests that they do care about their international reputation, such as it is.”

Clapper’s involvement gave North Korea a chance to raise broader diplomatic issues with a “high enough level official” to speak for the White House, Snyder said. But, he added, “a lot of their motivation is not wanting to have their leader impugned by this international condemnation.”

Two Americans, Kenneth Bae and Matthew Todd Miller, freed from North Korea returned home on Saturday after the surprise involvement of the top-ranking U.S. intelligence official who traveled to Pyongyang to secure their release. (Reuters)

It was unclear whether Clapper met with Kim or held any wider discussions with North Korean officials. The administration has repeatedly called for the release of Bae and Miller and described their detention as an “impediment” to such talks. Saturday’s announcement came one day before Obama travels to Asia for a three-country visit.

“Their release has been our focus every single day, and we’ve been working all the angles available to bring them home,” Secretary of State John F. Kerry told reporters traveling with him to China. “We’re pleased that this humanitarian gesture has taken place.”

Miller, who is from Bakersfield, Calif., was sentenced to six years hard labor in September after being convicted in a 90-minute trial on charges of committing “hostile acts” against the authoritarian North Korean government.

The 24-year-old had traveled to North Korea with a U.S.-based tour company in April. Later that month, the state-run Korean Central News Agency reported that he had torn up his tourist visa upon arrival and announced that he wanted to seek asylum. North Korea said Miller wanted to experience prison life as a means of investigating human rights violations in the country.

Bae, 46, a Korean American missionary from Lynnwood, Wash., was serving a 15-year sentence for “antigovernment activities.” He was detained in 2012 while leading a tour group in North Korea.

Bae had been held alone in a labor camp created especially for him, although Miller may have joined him there after being sentenced in September.

An administration source said Clapper was chosen for the trip in part because he can operate more covertly than many other high-ranking officials. His brief presence in North Korea’s capital was all the more remarkable because of his role overseeing a sprawling collection of U.S. spy agencies that regard North Korea as one of their highest-priority targets.

Documents released by former National Security Agency contractor Edward Snowden depicted North Korea as frustratingly opaque, with “critical” gaps in U.S. understanding of its nuclear and missile programs and little insight into the intentions of a young leader who had been largely shielded from view before taking power in 2011.

The nation has often used its pursuit of nuclear weapons to bargain for concessions from other countries, including fuel supplies and food for a population that has lost millions to starvation.

North Korea’s human rights violations were detailed in a 372-page U.N. report earlier this year that described brainwashing, torture, starvation and imprisonment for “crimes” such as questioning the system or trying to escape it.

Efforts are underway at the United Nations to refer North Korea’s leaders to the International Criminal Court on charges of crimes against humanity, saying it is time to take action against the regime “to a new level.”

North Korea now seems genuinely alarmed by the prospect that Kim and his cronies could be called to account and the fact that the regime has been answering charges — even if mainly by denying them — marks a change.

The calls for North Korea’s senior leaders to go before a tribunal have “shaken” them into discussion, said one Western diplomat who has dealt with Pyongyang and who spoke on the condition of anonymity.

Michael A. Fletcher and Carol Morello contributed to this report.