Sergeant Bergdahl is expected to return to an Army base as the case winds through the appeals process.

Sergeant Bergdahl was 23 and a private first class when he left his base in eastern Afghanistan in June 2009. Army investigators would later characterize his departure as a delusional effort to hike to a larger base and cause enough of a stir that he would get an audience with a senior officer to report what he felt were problems in his unit.

But the soldier, who is now 31, was captured by the Taliban within hours and spent five years as a prisoner, his treatment worsening after every attempt to escape. He was beaten with copper cables and held in isolation in a metal cage less than seven feet square. He suffered dysentery for most of his captivity, and cleaned feces off his hands with his own urine so that he could eat enough bread to survive.

The military searched for him, and several troops were wounded during those missions. One of them, Sgt. First Class Mark Allen, was shot through the head and lost the ability to walk, talk or take care of himself, and now has minimal consciousness. His wife, Shannon, testified that he is not even able to hold hands with her anymore. On a separate rescue mission, Senior Chief Petty Officer Jimmy Hatch, a Navy SEAL, suffered a leg wound that required 18 surgical procedures and ended his long career in special operations.

Army investigators quickly dismissed claims that troops had died searching for Sergeant Bergdahl — who was promoted during captivity — or that he had intended to defect to the Taliban. They suggested that he could be prosecuted for desertion and for some lesser crimes. But in March 2015, the Army raised the stakes, accusing him not only of desertion but also of misbehavior before the enemy, an ancient but rarely charged crime punishable by up to life in prison. In this case, the misbehavior was endangering the troops sent to search for him.

Even so, the sergeant’s defense seemed to have some momentum. The Army’s chief investigator on the case testified at Sergeant Bergdahl’s preliminary hearing that he did not believe any jail time was warranted, and the preliminary hearing officer suggested the whole episode might have been avoided “had concerns about Sergeant Bergdahl’s mental health been properly followed up.”

But at Fort Bragg, General Abrams ordered that Sergeant Bergdahl face a general court-martial on both charges.