WASHINGTON — The nation’s top military commanders unanimously support the controversial swap of Army Sgt. Bowe Bergdahl for five imprisoned Taliban leaders, letters released Thursday show.In the wake of criticism of the May 31 exchange, mainly from Republican lawmakers, Senate Armed Services Committee Chairman Carl Levin solicited the views of the Joint Chiefs of Staff.All seven members of the Joint Chiefs, who head the major military services, sent Levin letters in support of the deal.“Each of these military leaders emphasized a simple principle _ America does not leave its troops behind,” Levin said in a statement.Army Gen. Martin Dempsey, chairman of the Joint Chiefs, indicated that President Barack Obama and Defense Secretary Chuck Hagel had sought his opinion before signing off on the deal.“In arriving at my military advice, I balanced the risk of transferring the detainees with the importance of returning a U.S. soldier from enemy captivity,” Dempsey wrote to Levin. “I concluded the risk posed by the detainees’ future activity would be less grave than breaking faith with our forces in combat.”After almost five years in captivity, Taliban militants handed Bergdahl over to U.S. special forces in eastern Afghanistan. A video of the exchange, taken by the Taliban and released on one of its websites, went viral immediately.Once Bergdahl was airborne, five former officials of the deposed Taliban regime in Afghanistan were released from the U.S. military detention center at Guantanamo Bay, Cuba.Gen. Raymond Odierno, the Army chief of staff, told Levin that he had not been consulted about the exchange beforehand but that he backs it.“I firmly believe (that) the recovery of any American service member held as a captive, hostage or prisoner of war, regardless of the circumstances, is both a moral imperative and vital to keeping faith within our Army,” Odierno wrote the senator.Bergdahl was flown from Afghanistan to the Army military hospital in Landstuhl, Germany. He spent 12 days there undergoing treatment and getting debriefed before being flown to the Brooke Army Medical Center in San Antonio, Texas.Bergdahl, who is still being treated on an outpatient basis at the San Antonio hospital, is the subject of an Army investigation into his captivity and his mysterious June 30, 2009, disappearance from his outpost in Afghanistan’s Paktika province near the Pakistan border just before his capture.Some members of Bergdahl’s former unit have alleged that he went AWOL or possibly even deserted the Army before the Taliban nabbed him.Senior Army officials say Bergdahl could lose some or all of the back pay that accumulated during his captivity if the current probe finds him guilty of desertion.At a tense June 11 hearing, Hagel clashed with Republican senators claiming that the deal for Bergdahl’s freedom had violated longstanding U.S. policy never to negotiate with terrorists.Hagel also rebutted assertions that in authorizing the exchange, Obama had violated U.S. laws requiring him to give Congress at least 30 days’ notice of the release of Guantanamo detainees.Hagel, citing the need for secrecy before the Qatari-brokered deal was cemented, said Obama’s constitutional authority as commander in chief allowed him to keep Congress in the dark.Under the terms of the exchange, the five released Taliban must remain in Qatar for one year.Gen. James Amos, the Marine Corps commandant, said securing Bergdahl’s freedom fulfilled the “warrior code” of the nation’s armed forces that “we do not leave our people behind on the battlefield.”Amos, who said he was not consulted beforehand, expressed certainty that the deal’s risks were carefully weighed.“I am confident that the exigency of Sgt. Bergdahl’s release was balanced against an assessment of the dangers posed by the release of the Taliban detainees,” Amos wrote in his letter to Levin.