THE only American soldier held prisoner in Afghanistan has been freed from Taliban captivity in exchange for the release of five Afghan detainees from the US prison at Guantanamo Bay, Cuba, Obama administration officials said.

Sgt. Bowe Bergdahl was handed over to US special forces by the Taliban on Saturday evening, local time, in an area of eastern Afghanistan, near the Pakistan border.

US officials said the exchange was not violent and the 28-year-old Bergdahl was in good condition and able to walk.

US 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.”

The handover followed secret and indirect negotiations between the US and the Taliban, with the government of Qatar serving as the go-between.

Prisoner swap....US soldier Bowe Bergdahl has been released by the Taliban after almost five years as a prisoner of war. Picture: AFP/IntelCenterSource:AFP

Qatar is taking custody of the five Afghan detainees that had been held at Guantanamo Bay.

According to a senior US defense official traveling with US Defense Secretary Chuck Hagel in Singapore, once Sgt Bergdahl climbed onto 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.

Sgt Bergdahl, of Hailey, Idaho, is believed to have been held by the Haqqani network since June 30, 2009.

Haqqani operates in the Afghanistan-Pakistan border region and has been one of the deadliest threats to US troops.

Deal brokered... US President Barack spoke to Sgt Bergdahl’s parents overnight, informing them their son was finally on the way home. Picture: AFPSource:AFP

The network, which the US designated as a foreign terrorist organisation in 2012, claims allegiance to the Afghan Taliban, yet operates with some degree of autonomy.

Officials said Sgt Bergdahl was expected to be transferred to Bagram Air Field, the main US base in Afghanistan, for medical evaluations, then on to the United States.

Several dozen US special operations forces flew into Afghanistan by helicopter and made the transfer with the approximately 18 Taliban members.

The official said the commandos were on the ground for a short time before lifting off with Sgt Bergdahl.

The official added that the US still believes 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.

Officials said Mr Obama spoke with Sgt Bergdahl’s parents on Saturday, 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.

All the officials insisted on anonymity in order to discuss details of Sgt Bergdahl’s transfer.

The parents of the freed soldier, Bob and Jani Bergdahl, said in a statement that they were “joyful and relieved.”

“We cannot wait to wrap our arms around our only son,” they said.

The five Afghan detainees from Guantanamo were still at the base as of Saturday morning, but were being transferred into the custody of Qatari officials.

Under the conditions of their release, the detainees will be banned from traveling outside of Qatar for at least one year.

Long war...Washington is winding down its 32,000 troop deployment in Afghanistan after nearly 13 years of war, with US President Barack Obama announcing this week that all US forces will leave by the end of 2016. Picture: AFPSource:AFP

The detainees are believed to be the most senior Afghans still held at the prison. They are believed to be:

-Abdul Haq Wasiq, who served as the Taliban deputy minister of intelligence

-Mullah Norullah Nori, a senior Taliban commander in the northern city of Mazar-e-Sharif when the Taliban fought US forces in late 2001

-Khairullah Khairkhwa, who served in various Taliban positions including interior minister and had direct ties to Taliban leader Mullah Omar and Osama bin Laden

-Mohammed Nabi, who served as chief of security for the Taliban in Qalat, Afghanistan, and later worked as a radio operator for the Taliban’s communications office in Kabul

-Mohammad Fazl, whom Human Rights Watch says could be prosecuted for war crimes for presiding over the mass killing of Shiite Muslims in Afghanistan in 2000 and 2001 as the Taliban sought to consolidate their control over the country.

The circumstances surrounding Bergdahl’s capture remain something of a mystery.

There has been some speculation that he willingly walked away from his unit, raising the question of whether he could be charged with being absent without leave (AWOL) or desertion.