WASHINGTON (AP) — The only American solider held prisoner in Afghanistan has been freed from Taliban captivity in exchange for the release of five Afghan detainees from the U.S. prison at Guantanamo Bay, Cuba, Obama administration officials said Saturday.

This file image provided by IntelCenter on Dec. 8, 2010, shows a frame grab from a video released by the Taliban containing footage of a man believed to be Bowe Bergdahl (AP Photo/IntelCenter, File)

Sgt. Bowe Bergdahl was handed over to U.S. special forces by the Taliban Saturday evening, local time, in an area of eastern Afghanistan, near the Pakistani border. Officials said the exchange was not violent and the 28-year-old Bergdahl was in good condition and able to walk.

In a statement, President Barack Obama said 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 U.S. and the Taliban, with the government of Qatar serving as the go-between. Qatar is taking custody of the five Afghan detainees that had been held at Guantanamo Bay.

Bergdahl, of Hailey, Idaho, had been held by the Taliban since June 30, 2009. He is thought to have been captured by members of the Haqqani network, which operates in the Afghanistan-Pakistan border region and has been one of the deadliest threats to U.S. troops in the war.

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

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

Several dozen U.S. 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 Bergdahl

According to a senior defense official traveling with Defense Secretary Chuck Hagel in Singapore, once Bergdahl climbed onto the noisy helicopter he took a pen and wrote on a paper plate, the "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, Bergdahl broke down.

The official added that the U.S. still believes that Bergdahl was being held for the bulk of the time in Pakistan, but it was not clear when he was transported to eastern Afghanistan.

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.

Officials said Obama spoke with Bergdahl's parents Saturday, shortly after their son had been taken into U.S. custody. 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 Bergdahl's transfer.

(Copyright 2014 The Associated Press. All rights reserved. This material may not be published, broadcast, rewritten or redistributed)