(CNN) -- Sgt. Bowe Bergdahl, the American soldier held captive for nearly five years by militants during the Afghanistan war, has been released in exchange for five Guantanamo detainees, authorities said Saturday.
"Today the American people are pleased that we will be able to welcome home Sergeant Bowe Bergdahl," the White House said in a statement.
Bergdahl, the only remaining U.S. soldier captured during conflicts in Iraq and Afghanistan, was recovered by U.S. special operations forces about 10:30 a.m. ET in a peaceful handover in eastern Afghanistan, a senior Defense official told CNN. There were 18 Taliban members present.
Once on the American helicopter, Bergdahl, 28, used a paper plate to communicate because of the noise. He wrote on it, "SF?" meaning, "Special Forces?" The operators sitting with Bergdahl responded loudly: "Yes, we've been looking for you for a long time," according to the official.
Bergdahl broke down crying, the official recounted.
Secretary of Defense Chuck Hagel said in a separate statement that he had informed Congress of the decision to transfer five detainees from Guantanamo Bay to Qatar in exchange for Bergdahl, who was the only remaining American soldier captured from conflicts in Iraq and Afghanistan.
"A few hours ago, the family of Sgt. Bowe Bergdahl was informed by President Obama that their long wait for his return will soon be over," Hagel said.
"Sgt. Bergdahl is now under the care of the U.S. military after being handed over by his captors in Afghanistan. We will give him 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."
Bergdahl's parents happened to still be in Washington, having visited for Memorial Day.
A statement from Bob and Jani Bergdahl said: "We were so joyful and relieved when President Obama called us today to give us the news that Bowe is finally coming home! We cannot wait to wrap our arms around our only son. We want to thank Bowe's many supporters in Idaho, around the nation and around the world. We thank the Amir of Qatar for his efforts. And of course, we want to take this opportunity to thank all those in the many U.S. Government agencies who never gave up. Today, we are ecstatic!"
President Obama said in the White House statement, "On behalf of the American people, I was honored to call his parents to express our joy that they can expect his safe return, mindful of their courage and sacrifice throughout this ordeal."
Secretary of State John Kerry said the "cost of years of captivity to Sergeant Bowe Bergdahl and his family is immeasurable."
"As we look to the future in Afghanistan, the United States will continue to support steps that improve the climate for conversations between Afghans about how to end the bloodshed in their country through an Afghan-led reconciliation process," Kerry said in a statement.
In exchange for Bergdahl's release, five detainees at Guantanamo Bay will be released to Qatar. The U.S. has "appropriate assurances" that Qatar will be able to secure the detainees there, where they are under a travel ban for a year.
A U.S. Air Force aircraft carrying the detainees left the U.S. Navy base in Cuba on Saturday afternoon, a senior Defense official told CNN.
Hagel said the United States "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 United States believes Bergdahl had been held for the bulk of his captivity in Pakistan, the official said. It was unclear when he was moved to Afghanistan.
The U.S. government acknowledged in May 2012 that it was engaged in talks with the Taliban to free Bergdahl.
Saturday's transfer was brokered through the local Qatari government, the official said, after talks that began about a week ago.
U.S. officials had said this year that one route to getting Bergdahl back was through Qatari officials, who had been talking to the Taliban. But Bergdahl was believed to be held by operatives from the Haqqani network, an insurgent force affiliated with the Taliban and al Qaeda, and it was not clear whether Haqqani operatives would abide by any agreement among the United States, Qatar and the Taliban.
For now, Bergdahl is at a forward operating base in Afghanistan.
Bergdahl was deployed to Afghanistan in May 2009. He was 23 when he was captured by the Taliban after finishing a guard shift at a combat outpost on June 30, 2009, in Paktika province.
In July of that year, a U.S. military official said the soldier was being held by the clan of warlord Siraj Haqqani.
The United States has long declared that it won't negotiate with terrorists, which is what it considers the Taliban, but analysts have said the U.S. has effectively maneuvered around the edges of that declaration over the years.
"As the Administration has repeatedly affirmed, we will not transfer any detainee from Guantanamo unless the threat the detainee may pose to the United States can be sufficiently mitigated and only when consistent with our humane treatment policy," a senior administration official told CNN, adding that the detainees will be "subject to restrictions on their movement and activities."
Arizona Sen. John McCain, himself a former POW, in a statement called the released detainees "hardened terrorists who have the blood of Americans and countless Afghans on their hands."
"I am eager to learn what precise steps are being taken to ensure that these vicious and violent Taliban extremists never return to the fight against the United States and our partners or engage in any activities that can threaten the prospects for peace and security in Afghanistan," he said. "The American people, and our Afghan partners, deserve nothing less."
The Taliban had long demanded the release of five detainees at the U.S. military prison at Guantanamo Bay, Cuba. But U.S. officials said that releasing them would be difficult because Congress would have to be notified in advance, and lawmakers have previously resisted releasing them.
Bergdahl, of Wood River Valley, Idaho, appeared in diminished health in a video that the U.S. military obtained in January. His family also received a letter from him last year via the Red Cross.