WASHINGTON- U.S. Army Sergeant Bowe Bergdahl, held for nearly five years by the Taliban, is now in U.S. custody, President Barack Obama said today.

As part of Bergdahl's release, the United States is turning over five Taliban detainees at the U.S. facility in Guantanamo, Cuba, to the custody of Qatar, U.S. officials said.

Bergdahl's freedom follows months of indirect U.S.-Taliban talks with Qatar acting as intermediary, the officials said.

U.S. special operations forces took custody of Bergdahl in non-violent exchange in eastern Afghanistan, the officials said, adding that he was believed to be in good condition and undergoing a medical examination in Afghanistan.

Bergdahl, who is from Idaho, was the only known missing soldier in the Afghan war. He was captured under unknown circumstances in eastern Afghanistan by militants on June 30, 2009, about two months after arriving in the country.