The only American soldier held prisoner in Afghanistan has been freed and is in US custody, according to US officials.
The officials said Sgt Bowe Bergdahl’s release was part of a negotiation that includes the release of five Afghan detainees held at Guantanamo.
The negotiation between the US and the Taliban was mediated by the government of Qatar.
Bergdahl, 28, had been held by the Taliban since June 30, 2009. The officials said he is in good condition and able to walk.
President Barack Obama said Sgt Bergdahl's recovery ``is a reminder of America's unwavering commitment to leave no man or woman in uniform behind on the battlefield''.
Officials said the Taliban turned over the 28-year-old this evening in Afghanistan. Several dozen US special forces were involved in the exchange, which took place in eastern Afghanistan, near the Pakistan border.
Sgt Bergdahl, of Hailey, Idaho, is expected to be transferred to Bagram Air Field, the main US base in Afghanistan, then on to the United States.
He is thought to have been captured by members of the Haqqani network, which operates in the Afghanistan-Pakistan border region and has been one of the deadliest threats to US troops in the war.
The Haqqani network, which the State Department designated as a foreign terrorist organisation in 2012, claims allegiance to the Afghan Taliban, yet operates with some degree of autonomy.
Several dozen US special operations forces flew into Afghanistan by helicopter and made the transfer with approximately 18 Taliban members. The official said the commandos were on the ground for a short time, before lifting off with Sgt Bergdahl.
According to a senior defence official traveling with Defence Secretary Chuck Hagel in Singapore, once Sgt Bergdahl climbed on to the noisy helicopter he took a pen and wrote on a paper plate, the letters “SF?” – asking the troops if they were special operations forces.
They shouted back at him over the roar of the rotors: “Yes, we’ve been looking for you for a long time.”
Then, according to the official, Sgt Bergdahl broke down.
The official added that the US still believes that Sgt Bergdahl was being held for the bulk of the time in Pakistan, but it was not clear when he was transported to eastern Afghanistan.
The five Afghan detainees from Guantanamo were still at the US base as of this morning, but were being transferred into the custody of Qatari officials. Under the conditions of their release, the detainees will be banned from travelling outside of Qatar for at least one year.
Officials said Mr Obama spoke with Sgt Bergdahl’s parents shortly after their son had been taken into US custody. Sgt Bergdahl’s family was in Washington on a previously scheduled visit when they received the news.