President Barack Obama, flanked by the parents of Sgt. Bowe Bergdahl at the White House on Saturday, praised the diplomatic officials and troops who helped secure the release of the American soldier held captive for nearly five years by militants during the Afghanistan war.

Bergdahl was released in exchange for five Guantanamo detainees, officials said.

The government of Qatar, which helped broker the release, pledged to "put in place measures to protect our national security," Obama said at the White House Rose Garden.

"While Bowe was gone, he was never forgotten," the President said.

Bergdahl's mother, Jani, said, "We will continue to stay strong for Bowe while he recovers."

Bob Bergdahl said he was not sure whether his son still speaks English and spoke at one point in what appeared to be Pashtun.

"I'm your father, Bowe," the father said.

Members of the White House national security team -- including Chief of Staff Denis McDonough, National Security Adviser Susan Rice and counterterrorism adviser Lisa Monaco -- grew emotional when the parents thanked those who helped secure their son's release.

Bergdahl, the only remaining U.S. soldier captured during the conflicts in Iraq and Afghanistan, was recovered by U.S. special operations forces without incident about 10:30 a.m. ET at a "pick-up" point in eastern Afghanistan, near the border with Pakistan, a senior Department of Defense official told CNN. There were 18 armed Taliban members present.

One of 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.

'Cannot wait to wrap our arms around our only son'

Earlier, the White House said in a statement, "Today the American people are pleased that we will be able to welcome home Sergeant Bowe Bergdahl."

Secretary of Defense Chuck Hagel said 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.

After Bergdahl was handed over, a series of secret procedures were set in motion so each side knew the other was living up to the bargain, according to U.S. Defense officials. Qatari officials were already at Guantanamo and took custody of the detainees. They assured the Taliban that the detainees would be flown to Qatar.

The Afghan Taliban issued a statement on its website in Arabic and Pashto announcing with "great happiness and joy" the exchange of Bergdahl for five of its imprisoned senior leaders.

It said, "The Islamic Emirate of Afghanistan was and has been for a long time attempting to free all the imprisoned Afghan prisoners inside and outside the country."

"Sgt. Bergdahl is now under the care of the U.S. military after being handed over by his captors in Afghanistan," Hagel said. "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."

Photos:Americans detained abroad

Photos:Americans detained abroad

Kim Dong Chul, a South Korean-born American citizen detained in North Korea, is escorted to his trial April 29 in Pyongyang. A North Korean court sentenced Kim to 10 years in prison for what it called acts of subversion and espionage. North Korea watchers interpret the detainment of Americans and other foreign citizens as a collection of bargaining chips by the reclusive regime.

Hide Caption

1 of 27

Photos:Americans detained abroad

University of Virginia student Otto Frederick Warmbier was detained by North Korea after being accused of carrying out "a hostile act" against the government, state media reported. In March, he was sentenced to 15 years of hard labor for allegedly removing a political banner from a Pyongyang hotel.

Hide Caption

2 of 27

Photos:Americans detained abroad

Jason Rezaian, The Washington Post's bureau chief in Tehran, was released January 16 as part of a prisoner swap. Rezaian was convicted by an Iranian Revolutionary Court in October, according to Iran's state-run media. Rezaian was reportedly facing up to 20 years, but the sentence was not specified. The journalist was taken into custody in July 2014 and later charged with espionage; the Post has denied all allegations against him. His wife, Yeganeh Salehi, also was detained in July 2014 but later released.

Hide Caption

3 of 27

Photos:Americans detained abroad

Saeed Abedini, a U.S. citizen of Iranian birth, was freed as part of a prisoner swap that included Washington Post journalist Jason Rezaian on January 16. Abedini was sentenced to eight years in prison in January 2013. He was accused of attempting to undermine the Iranian government and endangering national security by establishing home churches. He was detained in Iran on September 26, 2012, according to the American Center for Law and Justice.

Hide Caption

4 of 27

Photos:Americans detained abroad

Amir Hekmati, a former U.S. Marine charged with spying, was freed as part of a prisoner swap that included Washington Post journalist Jason Rezaian on January 16. An Iranian court threw out a 2011 death sentence forHekmati, but he was secretly retried in Iran and convicted of "practical collaboration with the U.S. government," his sister told CNN on April 11. He was sentenced to 10 years in prison, she said. Hekmati was detained in August 2011 during a visit to see his grandmother. His family and the Obama administration deny accusations he was spying for the CIA.

Hide Caption

5 of 27

Photos:Americans detained abroad

Siamak Namazi, a Dubai-based businessman with dual U.S. and Iranian citizenship, was detained while visiting relatives in Tehran, the Wall Street Journal reported October 29, citing unnamed sources. The Washington Post also reported his detention, citing a family friend who spoke on condition of anonymity. The Post reported that it wasn't clear what Namazi is alleged to have done. His detention would bring to five the number of Americans detained or unaccounted for in the Islamic republic.

Hide Caption

6 of 27

Photos:Americans detained abroad

Scott Darden was taken hostage by Houthi rebels in Yemen in March 2015. He was captured while working for New Orleans-based Transoceanic Development, according to a source close to his family.

Hide Caption

7 of 27

Photos:Americans detained abroad

Retired FBI agent Robert Levinson has been missing since 2007. His family says he was working as a private investigator in Iran when he disappeared, and multiple reports suggest Levinson may have been working for the CIA. His family told CNN that they have long known that Levinson worked for the CIA, and they said it's time for the government to lay out the facts about Levinson's case. U.S. officials have consistently denied publicly that Levinson was working for the government, but they have repeatedly insisted that finding him and bringing him home is a "top" priority. The FBI increased its reward for information on Levinson from $1 million to $5 million.

Hide Caption

8 of 27

Photos:Americans detained abroad

Mothers Linda Boyle, left, and Lyn Coleman hold photo of their married children, Joshua Boyle and Caitlin Coleman, who were kidnapped by the Taliban in late 2012. Coleman was pregnant when she was kidnapped and is believed to have had a child in captivity.

Hide Caption

9 of 27

Photos:Americans detained abroad

Jailed since 2013 and sentenced to life for supporting the Muslim Brotherhood in Egypt, Mohamed Soltan was eventually released, the U.S. Embassy in Cairo said in May 2015. Soltan's family denies he belonged to the Brotherhood. Soltan had been a dual U.S. and Egyptian citizen, but he renounced his Egyptian citizenship as a condition of his release.

One of three Americans detained in North Korea, Jeffrey Edward Fowle was released and sent home, a State Department official told CNN in October 2014. Fowle was accused of leaving a Bible in a hotel where he was staying. North Korea announced Fowle's detention in June of that year, saying he had violated the law by acting "contrary to the purpose of tourism." Fowle told CNN: "I've admitted my guilt to the government and signed a statement to that effect and requested forgiveness from the people and the government of the DPRK."

Hide Caption

12 of 27

Photos:Americans detained abroad

In May 2013, a North Korean court sentenced Kenneth Bae, a U.S. citizen, to 15 years of hard labor for committing "hostile acts" against the state. North Korea claimed Bae was part of a Christian plot to overthrow the regime. In a short interview with CNN in September 2014, Bae said he is working eight hours a day, six days a week at a labor camp. "Right now what I can say to my friends and family is, continue to pray for me," he said. After months in detention, he and fellow American detainee Matthew Todd Miller were released in November.

Hide Caption

13 of 27

Photos:Americans detained abroad

Miller, an American sentenced to six years of hard labor in North Korea, was one of three Americans who spoke to CNN's Will Ripley in September 2014 and implored the U.S. government for help. The 24-year-old was accused of tearing up his tourist visa and seeking asylum upon entry to North Korea.

Hide Caption

14 of 27

Photos:Americans detained abroad

American journalist Peter Theo Curtis was handed over to U.N. peacekeepers in August 2014 after nearly two years in captivity. He is believed to have been captured in October 2012 and held by the al-Nusra Front, a Syrian rebel group with ties to al Qaeda.

Hide Caption

15 of 27

Photos:Americans detained abroad

Alan Gross, at right with Rabbi Arthur Schneier, was jailed while working as a subcontractor in Cuba in December 2009. Cuban authorities say Gross tried to set up illegal Internet connections on the island. Gross says he was just trying to help connect the Jewish community to the Internet. Former President Jimmy Carter and New Mexico Gov. Bill Richardson both traveled to Cuba on Gross' behalf. He was eventually released in December.

Hide Caption

16 of 27

Photos:Americans detained abroad

This undated image provided by the U.S. Army shows Sgt. Bowe Bergdahl, who had been held by insurgents in Afghanistan since 2009. The White House announced Bergdahl's release on May 31, 2014. Bergdahl was released in exchange for five senior Taliban members held by the U.S. military. In March 2015, the U.S. military charged Bergdahl with one count each of "Desertion with Intent to Shirk Important or Hazardous Duty," and "Misbehavior Before The Enemy by Endangering the Safety of a Command, Unit or Place."

Hide Caption

17 of 27

Photos:Americans detained abroad

U.S. tourist and Korean War veteran Merrill Newman arrives at the Beijing airport on December 7, 2013, after being released by North Korea. Newman was detained in October 2013 by North Korean authorities just minutes before he was to depart the country after visiting through an organized tour. His son Jeff Newman said the Palo Alto, California, man had all the proper paperwork and set up his trip through a North Korean-approved travel agency.

Hide Caption

18 of 27

Photos:Americans detained abroad

Y – Mexican authorities arrested Yanira Maldonado, a U.S. citizen, right, in May 2013, for alleged drug possession. She and her husband, Gary, were traveling from Mexico back to the United States when their bus was stopped and searched. She was released a few days later and is now back in the United States.

Hide Caption

19 of 27

Photos:Americans detained abroad

North Korea has arrested Americans before, only to release them after a visit by a prominent dignitary. Journalists Laura Ling, center, and Euna Lee, to her left, spent 140 days in captivity after being charged with illegal entry to conduct a smear campaign. They were freed in 2009 after a trip by former President Bill Clinton.

Hide Caption

20 of 27

Photos:Americans detained abroad

Former President Jimmy Carter negotiated the release of Aijalon Gomes, who was detained in 2010 after crossing into North Korea illegally from China. Analysts say high-level visits give Pyongyang a propaganda boost and a way to save face when it releases a prisoner.

Hide Caption

21 of 27

Photos:Americans detained abroad

Detained in April 2011, Eddie Yong Su Junwas released by North Korea a month afterward. His alleged crime was not provided to the media. The American delegation that secured his freedom included Robert King, the U.S. special envoy for North Korean human rights issues.

Hide Caption

22 of 27

Photos:Americans detained abroad

Without any apparent U.S. intervention, Robert Park was released by North Korea in 2010. The Christian missionary crossed into North Korea from China, carrying a letter asking Kim Jong Il to free political prisoners and resign. North Korea's state-run news agency said Park was released after an "admission and sincere repentance of his wrongdoings." Here, Park holds a photo of Kim and a malnourished child during a protest in Seoul.

Hide Caption

23 of 27

Photos:Americans detained abroad

Josh Fattal, center; Sarah Shourd, left; and Shane Bauer were detained by Iran while hiking near the Iraq-Iran border in July 2009. Iran charged them with illegal entry and espionage. Shourd was released on bail for medical reasons in September 2010; she never returned to face her charges. Bauer and Fattal were convicted in August 2011, but the next month they were released on bail and had their sentences commuted.

Hide Caption

24 of 27

Photos:Americans detained abroad

Haleh Esfandiari, an Iranian-American scholar, was detained at Iran's Evin Prison, spending months in solitary confinement before Iran released her on bail in August 2007. Esfandiari was visiting her ailing mother in Tehran when she was arrested and charged with harming Iran's national security.

Hide Caption

25 of 27

Photos:Americans detained abroad

Sixteen Americans were among the dozens arrested in December 2011 when Egypt raided the offices of 10 nongovernmental organizations that it said received illegal foreign financing and were operating without a public license. Many of the employees posted bail and left the country after a travel ban was lifted a few months later. Robert Becker, right, chose to stay and stand trial. He spent two years in prison and has since returned to the United States.

Hide Caption

26 of 27

Photos:Americans detained abroad

Filmmaker Timothy Tracy was arrested in Venezuela in April 2013 on allegations of funding opponents of newly elected President Nicolas Maduro, successor to the late Hugo Chavez. Tracy went to Venezuela to make a documentary about the political division gripping the country. He was released in June 2013.

JUST WATCHED

New hope for U.S. soldier held captive

MUST WATCH

JUST WATCHED

Bergen: 'It's been a long time coming'

MUST WATCH

Bergen: 'It's been a long time coming'01:57

Bergdahl's parents happened to still be in Washington, having visited for Memorial Day.

They said in an earlier statement: "We were so joyful and relieved when President (Barack) 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!"

Secretary of State John Kerry said the "cost of years of captivity to Sergeant Bowe Bergdahl and his family is immeasurable."

'Appropriate assurances' over five detainees

In exchange for Bergdahl's release, five detainees at Guantanamo Bay will be released to Qatar, authorities said. The United States 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.

Bergdahl was first transferred to Bagram Airfield, the main U.S. base in Afghanistan, for medical evaluation.

"His health is our number one priority at this time," a senior U.S. defense official said.

His "reintegration process" will include "time for him to tell his story, decompress, and to reconnect with his family through telephone calls and video conferences. At this time we believe that he will physically reunite with his family in Texas," the official said.

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.

An Afghan Taliban commander, not authorized to speak to the media, confirmed to CNN that Bergdahl was captured by the Afghan Taliban with links to the Haqqani network in Pakistan. Over the years, the captive was transferred back and forth between Afghanistan and Pakistan.

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.

Critics question the negotiations

The United States has long declared that it won't negotiate with groups linked to terrorists, but analysts have said the United States 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, 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."

A senior administration official told CNN, "With regard to whether or not we're negotiating with terrorists: Sergeant Bergdahl is a member of the military who was detained during the course of an armed conflict. The transfer of these individuals is not a concession -- it is fully in line with the President's goal of closing the detention facility at Guantanamo Bay."

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.

NATO leaders signed off last week on Obama's exit strategy from Afghanistan that calls for an end to combat operations next year and the withdrawal of the U.S.-led international military force by the end of 2014.

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.