Undated image from video footage taken from a Taliban-affiliated website shows a man who says he is Private First Class Bowe R. Bergdahl, a U.S. soldier captured by the Taliban in southeastern Afghanistan in late June 2013.Credit: Reuters

U.S. Army Sergeant Bowe Bergdahl, held for nearly five years by the Taliban after being captured in Afghanistan, has been released and is now in U.S. custody, President Barack Obama said on Saturday.

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

U.S. 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, who is from Idaho, was the only known missing U.S. soldier in the Afghan war that was launched soon after the Sept. 11, 2001 attacks on the United States. 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 in a statement.

"On behalf of the American people, I was honored 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 U.S. defense official said, without giving details.

Obama thanked Qatar for its role in Bergdahl's release, as well as the Afghan government.

The U.S. defense official said Bergdahl was able to walk and became emotional on his way to freedom.

"Once the 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."

Defense Secretary Chuck Hagel, traveling in Asia, said in a statement that Bergdahl would be given "all the support he needs to help him recover from this ordeal, and we are grateful that he will soon be reunited with his family."

Hagel said Qatar would take steps to ensure that U.S. national security would not be endangered by taking in the five Taliban detainees.