He said that he was particularly struck by the fact that unlike Mr. McCain and other prisoners of war who knew there were other American prisoners nearby even when they were in solitary confinement, Sergeant Bergdahl was alone, bereft of any solace that could come from knowing there were fellow soldiers in the same situation. “In this case, Bergdahl was by himself,” Mr. Hagel said. “As far as we know, there were no other Americans.”

Even as new details were emerging about the operation to swap Sergeant Bergdahl for five detainees at Guantánamo Bay — the leader of the Special Forces team that whisked Sergeant Bergdahl by helicopter from the Pakistani border region had been in constant communication with the Taliban in the minutes leading up to the swap — Defense Department officials were also weighing the overall messiness of the case of Sergeant Bergdahl, who went missing from his unit five years ago, amid reports that he walked off his base voluntarily, in violation of Army regulations.

A senior Defense Department official indicated on Sunday that the Army would probably not be punishing the sergeant for any violations of rules. “Whatever he may have done, I think he’s more than paid for it,” the official said. “Five years is a long time.”

By the time Mr. Hagel arrived at Bagram on Sunday afternoon, the sergeant had been transported to Germany, as military officials and doctors determined that the sooner they got him out of Afghanistan, the better. Mr. Hagel said he planned to talk to Sergeant Bergdahl soon, but would not interfere with the sergeant’s recovery.