US Army Sergeant Bowe Bergdahl, 28, was handed over to US forces in good health, the officials said.
The five Afghan detainees have been released from the US prison at Guantanamo Bay, Cuba.
They were handed over to Qatar, which mediated the transfer.
Sgt Bergdahl was the only US soldier being held by the Taliban in Afghanistan.
Officials said he was in good condition and able to walk. He is expected to be transferred to Bagram Air Field, the main US base in Afghanistan, and then on to the United States.
'Broke down'
In a statement, 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''.
Officials said the Taliban had handed him over on Saturday evening, local time, in eastern Afghanistan. Several dozen US
A senior official told the BBC that, once aboard the US helicopter, Sgt Bergdahl wrote the letters SF - meaning special operations forces - followed by a question mark on a paper plate and showed them to the pilots, who replied: "Yes, we've been looking for you for a long time."
The senior official said that "at that point, Sgt Bergdahl broke down".
Sgt Bergdahl, of Hailey, Idaho, had been held since 30 June 2009.
US Defence Secretary Chuck Hagel said Sgt Bergdahl would be given "all the support he needs to help him recover from this ordeal, and we are grateful that he will soon be reunited with his family".
He thanked the emir of Qatar for his role in enabling the transfer to take place.
On the five Guantanamo detainees, he said: "The United States has co-ordinated closely with Qatar to ensure that security measures are in place and the national security of the United States will not be compromised."
Gossip-Lanka

