United States Army Sergeant Bowe Bergdahl, held for nearly five years by the Taliban after being captured in Afghanistan, has been released and is now in US custody, President Barak Obama said yesterday.

As part of Bergdahl's release, the United States has turned over five Taliban detainees at the US prison in Guantanamo Bay, Cuba, to the custody of Qatar, US officials said.

Bergdahl's freedom follows months of indirect US-Taliban talks with Qatar acting as intermediary, they added.

US special operations forces took custody of Bergdahl in a non-violent exchange with Taliban members in eastern Afghanistan, the officials said, adding that he was believed to be in good condition. He was now undergoing a medical examination in Afghanistan.

Bergdahl, from Idaho, was the only known missing US soldier in the Afghan war that was launched soon after the September 11, 2001 attacks on the US. He was captured under unknown circumstances in eastern Afghanistan by militants on June 30, 2009, about two months after arriving in the country.

"Today the American people are pleased that we will be able to welcome home Sergeant Bowe Bergdahl, held captive for nearly five years," Obama said. "On behalf of the American people, I was honoured to call his parents to express our joy that they can expect his safe return, mindful of their courage and sacrifice throughout this ordeal."

The Bergdahl family was in Washington when news of the release broke, a senior US defence official said. Obama thanked Qatar for its role in Bergdahl's release, as well as the Afghan government. The US defence official said Bergdahl was able to walk and became emotional on his way to freedom.

"Once he was on the helicopter, he wrote on a paper plate, 'SF?'" the official said, referring to the abbreviation for special forces.

"The operators replied loudly, 'Yes, we've been looking for you for a long time.' And at this point, Sergeant Bergdahl broke down."

Defence Secretary Chuck Hagel, traveling in Asia, said Bergdahl would be given "all the support he needs".