Afghanistan's government protested against a U.S. deal to free five high-ranking Taliban militants in exchange for a U.S. soldier late Sunday, arguing the transfer of the men from a Guantanamo Bay jail to Qatar violated international law.

The five prisoners were flown to Qatar on Sunday as part of the agreement to release army Sgt. Bowe Bergdahl, the only known U.S. prisoner of war in Afghanistan, held captive for five years. Bergdahl was flown out of Afghanistan to a military hospital in Germany on Sunday.

The prisoner swap has stoked anger in Afghanistan, where many view the deal as a further sign of a U.S. desire to disengage from Afghanistan as quickly as possible. Washington has mapped out a plan to fully withdraw all of its troops by the end of 2016.

"No government can transfer citizens of a country to a third country as prisoners," the Afghan Foreign Affairs Ministry said in a statement issued late on Sunday.

Deepening distrust

Afghan President Hamid Karzai, who was excluded from the deal to avoid leaks according to the U.S. government, has not commented on the prisoner swap, although the foreign ministry statement was emailed from his media office.

Karzai, who is due to step down as leader later this year, has been fiercely critical of the U.S. administration in recent years, and the prisoner swap will only serve to deepen the distrust between the sides.

Under the terms of the deal cut by Qatari intermediaries, the five Taliban detainees were released from Guantanamo Bay, Cuba, where they had been held since it opened in 2002, and flown to Qatar where they must stay for a year.

Senior officials at the Afghan intelligence agency say they believe the men will return to the battlefield and bolster the insurgency just as most foreign combat troops prepare to exit by the end of this year.

All five prisoners were classed as "high-risk" and "likely to pose a threat" by the Pentagon and held senior positions in the Taliban regime before it was toppled by a U.S.-led coalition in 2001.

At least two of them are suspected of committing war crimes, including the murder of thousands of Afghan Shias, according to leaked U.S. military cables.

Political turmoil

The swap has similarly drawn protest from U.S. Republican politicians who have called it negotiating with terrorists and warned the freed men will likely return to battle.

Karzai and Obama

Afghan President Hamid Karzai has been increasingly vocal in his public criticisms of U.S. foreign policy in recent years. Many believe that U.S. President Obama's decision to trade five Taliban prisoners for an American PoW will only further deepen tensions between the countries. (Jason Reed/Reuters)

While Bergdahl's release on Saturday was celebrated by his family and his hometown, and could be seen as a coup for President Barack Obama as he winds down America's longest war, Senator John McCain and other Republicans questioned whether the administration had acted properly in releasing the militants.

"These are the highest high-risk people. Others that we have released have gone back into the fight," said McCain, a former prisoner of war and Vietnam War veteran.

"That's been documented. So it's disturbing to me that the Taliban are the ones that named the people to be released," he said on CBS's Face the Nation.

Congressmen Mike Rogers, a Michigan Republican and chairman of the House Intelligence Committee, said under the law, the Obama administration is required to give Congress 30 days' notice before moving any prisoner out of Guantanamo Bay.

He told The Washington Times it's "naive" to think the men released by the U.S. ill not "re-engage in the fight in some way."

Perhaps complicating matters, a former senior defence official told The Associated Press that a 2010 Pentagon investigation concluded that Bergdahl had walked away from his unit.

'He deserted,' officer in unit alleges

The source, who spoke on condition of anonymity and was not authorized to discuss the matter by name, said the military initially searched for Bergdahl vigorously before deciding not to mount an extraordinary rescue campaign in 2009.

An article on the Daily Beast website written by Nathan Bradley Bethea, who served in Bergdahl's unit, said on Monday that Bergdahl was not on patrol the night he first went missing, contrary to some reports.

"Bergdahl was relieved from guard duty, and instead of going to sleep, he fled the outpost on foot. He deserted," Bethea writes in the piece.

He adds: "Bergdahl was a deserter, and soldiers from his own unit died trying to track him down."

As the Obama administration sought to counter the criticism, Bergdahl was flown to Landstuhl Regional Medical Centre in Germany for medical treatment. After receiving care he would be transferred to another facility in San Antonio, Texas, U.S. defence officials said, without giving a date for his return to the United States.

U.S. Defence Secretary Chuck Hagel said he hoped the exchange might lead to breakthroughs in reconciliation with the militants and rejected accusations from Republicans that it resulted from negotiations with terrorists, saying the swap had been worked out by the government of Qatar.

Tireless campaigners for their son's freedom, Bob and Jani Bergdahl thanked all who were behind the effort to retrieve him. "You were not left behind," Bob Bergdahl told reporters, as if speaking to his son. "We are so proud of the way this was carried out." He spoke in Boise, Idaho, wearing a long bushy beard he'd grown to honour his son, as residents in the sergeant's hometown of Hailey prepared for a homecoming celebration.

With files from The Associated Press and CBC News