The detainees were released from the US prison at Guantanamo Bay, Cuba and handed over to Qatar, which mediated the transfer.
US Army Sergeant Bowe Bergdahl, 28, was handed over to US forces in good health, BBC quoted the US officials as saying. Sgt. Bergdahl was the only US soldier being held by the Taliban in Afghanistan.
Officials said the Taliban handed him over Saturday evening.
US President Barack Obama, in a statement said: "On behalf of the American people, I was honoured to call his parents to express our joy that they can expect his safe return."
"Sergeant Bergdahl's recovery is a reminder of America's unwavering commitment to leave no man or woman in uniform behind on the battlefield."
Bergdahl, who was captured in Afghanistan June 30, 2009, is now under the care of the US military after being handed over by his captors in Afghanistan, Xinhua quoted Secretary of Defense Chuck Hagel as saying in a statement.
As part of Bergdahl's release, the US agreed to turn over five Taliban detainees at the US prison in Guantanamo Bay, Cuba, to the custody of Qatar.
Hagel said, "As of today, I informed Congress of the decision to transfer five detainees from Guantanamo Bay to Qatar," with which Washington has coordinately closely to ensure that security measures are in place and that the national security of the United States will not be compromised.
Obama, in his statement, also thanked the Emir of Qatar, whose "personal commitment to this effort is a testament to the partnership between our two countries".
Obama also thanked the government of Afghanistan throughout the efforts to secure the release, voicing hope "Bergdahl's recovery could potentially open the door for broader discussions among Afghans about the future of their country by building confidence that it is possible for all sides to find common ground."