Get breaking news alerts and special reports. The news and stories that matter, delivered weekday mornings.

President Barack Obama on Tuesday defended his decision to swap five Taliban militants for Army Sgt. Bowe Bergdahl, who apparently walked away from his unit, even as the military promised an inquiry into whether the soldier deserted.

Obama cited a “sacred” obligation not to leave American soldiers behind. Speaking in Poland, he also expressed confidence that the United States could still go after the militants if they pose a future threat to national security.

“Regardless of the circumstances, whatever those circumstances may turn out to be, we still get an American soldier back if he’s held in captivity,” told reporters in Warsaw. “We don’t condition that.”

Republicans in Congress and former members of Bergdahl’s platoon have expressed outrage at the swap and at depictions of Bergdahl, the only American prisoner of war in Afghanistan, as a hero.

American military officials have told NBC News that Bergdahl, before his capture by the Taliban in June 2009, walked away from his unit without his weapon. He was handed over in exchange for five militants held at Guantanamo Bay, Cuba.

The Army is preparing a full, high-level inquiry into the circumstances of Bergdahl’s disappearance and his personal conduct, NBC News learned Tuesday. It will also investigate the circumstances that led to the deaths of six soldiers during the search for Bergdahl.

Let our news meet your inbox. The news and stories that matters, delivered weekday mornings. This site is protected by recaptcha

The inquiry would determine whether a formal investigation into possible criminal charges against Bergdahl is warranted. If Bergdahl is found guilty of misconduct, the options for punishment would range from administrative disciplinary action to a court-martial.

Army officials told NBC News that the priority is to get Bergdahl back to full health and reunited with his family.

Sgt. Josh Korder, who served in Bergdahl’s platoon, told TODAY that Bergdahl became disillusioned with combat and “just wanted to go on an adventure and walk the mountains of Afghanistan and not have anybody to answer to.”

Korder has the names of three of his six fallen comrades tattooed on his back.

“We all served together, and we were all in it together over there, and he broke that bond by leaving us,” he said. Speaking of the militants, he said, “You’re just going to let these guys go for somebody who you’re already saying you know walked away. That’s just not right.”

Bergdahl, 28, was a private first class when he disappeared and was promoted twice in captivity. He is recovering at an American military hospital in Germany, where he is receiving psychological care and evaluation, and will eventually be reunited with his parents, who live in Idaho.

Gen. Martin Dempsey, the chairman of the Joint Chiefs of Staff, said in a post on his Facebook page that the Army “will not look away from misconduct if it occurred.” He said that the circumstances surrounding Bergdahl’s release were unique.

“This was likely the last, best opportunity to free him,” the general said. “As for the circumstances of his capture, when he is able to provide them, we’ll learn the facts. Like any American, he is innocent until proven guilty.”

Congressional Republicans have said that Obama skirted the law by failing to give Congress 30 days’ notice before releasing a prisoner from Guantanamo. The five, all high-level Taliban militants, were sent to Qatar.

Administration officials, including both the president and Defense Secretary Chuck Hagel, have said that they seized a short window to act because Bergdahl’s health was deteriorating.

Obama also said Tuesday in Poland that Congress had been consulted “for some time” about a possible prisoner exchange.

The Associated Press contributed to this report.