Bowe Bergdahl is escorted to the Fort Bragg military courthouse on October 16, 2017. Photo: Sara D. Davis/Getty Images

Army sergeant Bowe Bergdahl, who spent five years as a Taliban captive after abandoning his post in Afghanistan, pleaded guilty on Monday to desertion and misbehavior before the enemy.

The 31-year-old faces a maximum penalty of five years in prison for desertion, and life in prison for misbehavior before the enemy, a rarely used charge applied when troops endanger other service members through misconduct.

Bergdahl’s guilty pleas were not part of a deal with prosecutors. His punishment will be decided by an Army judge at Fort Bragg following a hearing set to begin next week.

“I understand that leaving was against the law,” Bergdahl told the judge, Colonel Jeffery Nance, on Monday. He’s said previously that his intention was to walk to a larger base about 18 miles away to report what he saw as a leadership problem in his unit. But within hours of leaving his base on June 29, 2009, Bergdahl was captured by armed Taliban fighters. They turned him over to the Haqqani network, who subjected him to what one U.S. official said was the worst abuse of an American service member since the Vietnam War.

Bergdahl said he did not anticipate that U.S. forces would launch an intense manhunt after he left. “I believed they would notice me missing, but I didn’t believe they would have reason to search for one private,” he said.

Army prosecutors argue that the effort to find Bergdahl derailed the war effort, and left some searchers seriously wounded. Prosecutors will present the wounds suffered by Army Master Sergeant Mark Allen, who was shot in the head and is now wheelchair bound and unable to speak, and Senior Chief Petty Officer Jimmy Hatch, a Navy SEAL who suffered a serious leg wound that required multiple surgeries, as evidence.

Defense lawyers argue that Bergdahl isn’t directly responsible for their injuries. They also say the Army is partly responsible because they allowed him to enlist after he was discharged from Coast Guard basic training for having “adjustment disorder with depression.” He was later diagnosed with schizotypal personality disorder.

Bergdahl was released in May 2014, after President Obama made the controversial decision to trade five Guantánamo Bay detainees for his return. Defense lawyers previously tried to argue that Bergdahl could not receive a fair trial after President Trump called him a “dirty rotten traitor” and publicly called for his execution on several occasions. Colonel Nance said Trump’s remarks were “disturbing,” but did not warrant dismissing the charges.

In a newly released interview filmed by a British filmmaker last year, Bergdahl criticized Trump. “We may as well go back to kangaroo courts and lynch mobs that got what they wanted,” Bergdahl says. “The people who want to hang me — you’re never going to convince those people.”

He also responded to the rumors that he fought against the U.S. alongside members of the Taliban, which military officials say are false. “You know, it’s just insulting, frankly,” Bergdahl said. “It’s very insulting, the idea that they would think I did that.”

Retired Army specialist Cody Full, who was in Bergdahl’s platoon in Afghanistan, told CNN that he still faults him for putting “thousands and thousands of people’s lives at risk.”

“He was a coward nine years ago when he deserted, and I think he showed he’s still a coward,” Full said. “He refuses to take responsibility for his actions.”