The only US soldier held prisoner in Afghanistan has been freed as part of a swap deal with the Taliban, brokered by the government of Qatar.
Bowe Bergdahl's release was part of a negotiation that included the freeing of five high-profile Afghan prisoners held in Guantanamo Bay, Cuba, the US government said.
The US president, Barack Obama, thanked Qatar's Emir, Sheikh Tamim bin Hamad Al Thani, for his commitment to the mediation between the US and the Taliban.
They can expect his safe return, mindful of their courage and sacrifice throughout this ordeal,
The 28-year-old Bergdahl, a sergeant in the US army, had been held by the Taliban since June 30, 2009. He was handed to US troops by the Taliban on Saturday evening in an area of eastern Afghanistan, near the Pakistan border
Officials said the exchange was not violent and Bergdahl was in good condition and able to walk.
He was on his way to an American military hospital in Germany after receiving medical care at Bagram Air Base, the main US base in Afghanistan.
The Taliban prisoners had also departed the Guantanamo prison and are aboard a US military C-17 aircraft en route to authorities in Qatar. They were named on Saturday as Mohammad Fazl, Mullah Norullah Noori, Mohammed Nabi, Khairullah Khairkhwa and Abdul Haq Wasiq.
All were high-ranking members of the Taliban government toppled by the US in 2001. Fazl was the deputy defence minister, while Noori was the governor of Balkh province.
The Taliban said in a statement that their release brought "great joy".
At a White House press conference with Bergdahl's parents Bob and Jani, Obama said: "He wasn't forgotten by his community in Idaho, or the military, which rallied to support the Bergdahls through thick and thin. And he wasn't forgotten by his country, because the United States of America does not ever leave our men and women in uniform behind."
"I'm also grateful for the tireless work of our diplomats, and for the cooperation of the government of Qatar in helping to secure Bowe's release.
"We've worked for several years to achieve this goal, and earlier this week I was able to personally thank the Emir of Qatar for his leadership in helping us get it done," Obama said.
"The Qatari government has given us assurances that it will put in place measures to protect our national security."
A senior White House official also told Al Jazeera that the US administration would not transfer any prisoners from Guantanamo "unless the threat they may pose to the US can be mitigated".
He said the Taliban prisoners would be "subject to restrictions on their movement and activities".
The deal was agreed through indirect talks with the Taliban's political commission, the official said.
Bergdahl's parents thanked everyone domestically and internationally who was involved in their son's rescue.
"The complicated nature of this recovery will never be comprehended," Bob Bergdahl said.
Omar Samad, the senior Central Asia fellow of the New America Foundation, told Al Jazeera that the exchange was "good news for the families on all sides".
Samad said the fact that Qatar was able to broker the exchange meant there was a growing momentum within the Taliban for political talks, as the organisation went through its own transitions with some military commanders promoted and others demoted.
"It's too early to make strong categorical conclusions - peace will take time, political talk will take time - but with this exchange we see it's shifting and changing," he said.