WASHINGTON, May 31 (Reuters) - The last U.S. prisoner of war from America's waning Afghan war was handed over to U.S. Special Operations forces in Afghanistan on Saturday in a dramatic swap for five Taliban detainees who were released from Guantanamo Bay prison and flown to Qatar.

Army Sergeant Bowe Bergdahl had been held for nearly five years by Afghan militants and his release followed years of on-off negotiations.

U.S. special forces took custody of Bergdahl in a non-violent exchange with 18 Taliban members in eastern Afghanistan, senior U.S. officials said, adding that he was believed to be in good condition. He was now undergoing a medical examination in Afghanistan.

Bergdahl, 28, was handed over at about 6 p.m. local time on Saturday, which was at 10:30 a.m. Washington time, a senior official said. The U.S. forces, who had flown in by helicopter, were on the ground very briefly, said the officials, who would not specify the precise location of the handover.

A U.S. defense official said Bergdahl was able to walk and became emotional on his way to freedom.

"Once he was on the helicopter, he wrote on a paper plate, 'SF?'" the official said, referring to the abbreviation for special forces.

"The operators replied loudly, 'Yes, we've been looking for you for a long time.' And at this point, Sergeant Bergdahl broke down."

Hours later, a second U.S. defense official said the five Taliban detainees, now formally in Qatari custody, had departed the Guantanamo prison for foreign terrorism suspects. They were aboard a U.S. military C-17 aircraft and were en route to the Gulf emirate.

President Barack Obama announced the release, saying he had called Bergdahl's parents to let them know their son was free.

Bergdahl, who is from Idaho, was the only known missing U.S. soldier in the Afghan war that was launched soon after the Sept. 11, 2001 attacks on the United States to dislodge the Taliban - accused of sheltering al Qaeda militants - from power.

He was captured under unknown circumstances in eastern Afghanistan by militants on June 30, 2009, about two months after arriving in the country.

TALIBAN PRISONERS

Bergdahl's release could be a national security boost for Obama, whose foreign policy has been widely criticized in recent months.

But some members of Congress have in the past worried over the potential release of the five Taliban detainees, particularly Mohammed Fazl, a so-called "high-risk" detainee held at Guantanamo since early 2002. Fazl is alleged to be responsible for the killing of thousands of Afghanistan's minority Shiite Muslims between 1998 and 2001.

While welcoming Bergdahl's release, Representative Mike Rogers, the Republican chairman of the House Intelligence Committee, said, "I am extremely troubled however that the United States negotiated with terrorists and agreed to swap five senior Taliban leaders who are responsible for the deaths of many Americans."

U.S. officials referred to the release of the Taliban detainees as a transfer and noted they would be subject to certain restrictions in Qatar. One of the officials said that would include a minimum one-year ban on them traveling outside of Qatar as well as monitoring of their activities.

But Rogers said he had "little confidence" in such assurances.

Under U.S. law, the Obama administration is supposed to notify Congress 30 days in advance of the transfer of any detainee from Guantanamo. In this case, a U.S. official said such notification was made on Saturday after Bergdahl was in U.S. custody - a move that could anger some lawmakers.

"Due to a near-term opportunity to save Sergeant Bergdahl's life, we moved as quickly as possible. The administration determined that given these unique and exigent circumstances, such a transfer should go forward notwithstanding the notice requirement," a senior U.S. official said.

Bergdahl's freedom followed a renewed round of indirect U.S.-Taliban talks in recent months, with Qatar acting as intermediary, the officials said. It also came just days after another step in the winding down of the war.

Obama announced this week that he would keep 9,800 U.S. troops in Afghanistan, mostly to train Afghan forces, after NATO combat operations cease at the end of 2014. The last soldiers, aside from a small presence at U.S. diplomatic posts, will leave at the end of 2016.

"Today the American people are pleased that we will be able to welcome home Sergeant Bowe Bergdahl, held captive for nearly five years," Obama said in a statement.

FAMILY, HOMETOWN CELEBRATE

The Bergdahl family was in Washington when news of the release broke, U.S. officials said, without giving details.

"We were so joyful and relieved when President Obama called us today to give us the news that Bowe is finally coming home!" Bob and Jami Bergdahl said in a statement released through the Idaho National Guard. "We cannot wait to wrap our arms around our only son."

It was not yet known when he would be coming back to the United States. But in his hometown, Hailey, Idaho, news of the release prompted celebration.

"Once we heard about it. We were pretty excited," said 17-year-old Real Weatherly, who was making signs Saturday morning and blowing up balloons to hang outside the shop where she works.

COMPLEX NEGOTIATIONS

The Afghan Taliban on Saturday confirmed it had freed Bergdahl. "This is true. After several rounds of talks for prisoners' swap, we freed US soldier and our dear guest in exchange of five commanders held in Guantanamo Bay since 2002," a senior Taliban commander said.

Declining to be identified, he said talks for the prisoners' release had been going on for the past several weeks.

The Taliban commander said Bergdahl had mostly been held in the tribal areas between Pakistan and Afghanistan after what he termed his "dramatic" kidnapping from Afghanistan's Paktika province in June 2009.

Reuters first reported the potential deal involving the five Taliban detainees in December 2011.

A second senior U.S. official said the negotiations for Bergdahl's release revived last November when the Taliban signaled it wanted to resume talks on prisoners. But it was unclear why the Taliban moved now to conclude a deal that Washington had been seeking for years.

While U.S. and Taliban envoys have met directly in the past, there were no direct U.S.-Taliban contacts during the most recent negotiations, U.S. officials said. Messages were passed via Qatari officials.

The final stage of negotiations, which took place in the Qatari capital of Doha, began one week ago, the U.S. officials said. Obama and Qatar's emir spoke on Tuesday and reaffirmed the security conditions under which the Taliban members would be placed, they said. (Additional reporting by Roberta Rampton and David Brunnstrom; Editing by Frances Kerry)

We welcome comments that advance the story through relevant opinion, anecdotes, links and data. If you see a comment that you believe is irrelevant or inappropriate, you can flag it to our editors by using the report abuse links. Views expressed in the comments do not represent those of the Thomson Reuters Foundation. For more information see our Acceptable Use Policy.