A US soldier captured nearly five years ago in Afghanistan has been freed in exchange for five Taliban inmates held at the Guantanamo prison in a dramatic deal brokered by Qatar.

US Army Sergeant Bowe Bergdahl was in ‘‘good’’ condition after Taliban fighters handed him over to ‘‘a few dozen’’ US special operations forces at an undisclosed location in eastern Afghanistan, defence officials said.

In announcing the breakthrough, President Barack Obama thanked Qatar’s emir, Sheikh Tamim bin Hamad Al-Thani, for helping to bring home the only American to be held captive by the Taliban in the 13-year-old war.

Freed by the Taliban: Sergeant Bowe Bergdahl was held for five years. Photo: AP

‘‘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.

Advertisement

Previous attempts to secure Bergdahl’s release through a swap with the Taliban had failed but this time, Qatar was able to secure an agreement.

A senior administration official confirmed that, ‘‘in connection’’ with the army sergeant’s return, the United States had transferred five Afghan Guantanamo detainees to the Arab emirate.

Sergeant Bergdahl in a 2009 video released by the Taliban. Photo: Reuters

‘‘With the personal commitment of the emir of Qatar, with whom the president spoke on Tuesday, we were thankfully able to obtain Sgt. Bergdahl’s release,’’ the official said in an email.

An opportunity arose several weeks ago to resume talks on Bergdahl’s release, the official said, ‘‘and we seized it.’’

Bergdahl disappeared in June 2009 from a base in Afghanistan’s eastern Paktika province near the Pakistan border, with the Taliban later saying they had captured him.

‘‘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.’’

Bergdahl’s parents said they were joyful and relieved to hear that their son was a free man.

‘‘We cannot wait to wrap our arms around our only son,’’ they said in a statement quoted by CNN.

But soon after the news broke, Obama faced criticism over the transfer of the Taliban inmates from the US prison in Guantanamo Bay, Cuba.

The senator demanded to know what steps were being taken to ‘‘ensure that these vicious and violent Taliban extremists never return to fight against the United States and our partners.’’

US Defense Secretary Chuck Hagel said the United States had ‘‘coordinated closely with Qatar to ensure that security measures are in place and the national security of the United States will not be compromised.’’

The senior administration official concurred, saying ‘‘we will not transfer any detainee from Guantanamo unless the threat the detainee may post to the United States can be sufficiently mitigated.’’

According to a State Department official, the five transferred detainees are Mohammad Fazl, Mullah Norullah Noori, Mohammed Nabi, Khairullah Khairkhwa, and Abdul Haq Wasiq.

A Taliban source in the Pakistani city of Quetta told AFP that all five had been officials in the Taliban regime driven out of power in the US-led invasion of Afghanistan after the September 11 attacks, and that they were influential among the Taliban ranks.

News of their transfer was welcomed with ‘‘great happiness’’ by the militants, who had long sought their release from Guantanamo Bay as a condition for launching peace talks.

Their transfer leaves 149 detainees in the US military prison in Cuba, including 12 Afghan nationals, of whom four have been approved for transfer.