WASHINGTON (AP) — Army Sgt. Bowe Bergdahl, who was held captive by the Taliban for half a decade after abandoning his Afghanistan post, is expected to plead guilty to desertion and misbehavior before the enemy, two individuals with knowledge of the case said.

Bergdahl’s decision to plead guilty rather than face trial marks another twist in an eight-year drama that caused the nation to wrestle with difficult questions of loyalty, negotiating with hostage takers and America’s commitment not to leave its troops behind. President Donald Trump has called Bergdahl a “no-good traitor” who “should have been executed.”

The decision by the 31-year-old Idaho native leaves open whether he will return to captivity for years — this time in a U.S. prison — or receive a lesser sentence that reflects the time the Taliban held him under brutal conditions. He says he had been caged, kept in darkness, beaten and chained to a bed.

Bergdahl could face up to five years on the desertion charge and a life sentence for misbehavior.

Freed three years ago, Bergdahl had been scheduled for trial in late October. He had opted to let a judge rather than a military jury decide his fate, but a guilty plea later this month will spare the need for a trial.

Sentencing will start on Oct. 23, according to the individuals with knowledge of the case. They weren’t authorized to discuss the case and demanded anonymity. During sentencing, U.S. troops who were seriously wounded searching for Bergdahl in Afghanistan are expected to testify, the individuals said.

It was unclear whether prosecutors and Bergdahl’s defense team had reached any agreement ahead of sentencing about how severe a penalty prosecutors will recommend.

An attorney for Bergdahl, Eugene Fidell, declined to comment on Friday. Maj. Justin Oshana, who is prosecuting the case, referred questions to the U.S. Army, which declined to discuss whether Bergdahl had agreed to plead guilty.

“We continue to maintain careful respect for the military-judicial process, the rights of the accused and ensuring the case’s fairness and impartiality during this ongoing legal case,” said Paul Boyce, an Army spokesman.

Bergdahl was a 23-year-old private first class in June 2009 when, after five months in Afghanistan, he disappeared from his remote infantry post near the Pakistan border, triggering a massive search operation.

Videos soon emerged showing Bergdahl in captivity by the Taliban, who ruled Afghanistan in the years before the Sept. 11, 2001, attacks and harbored al-Qaida leaders including Osama bin Laden as they plotted against America. For years, the U.S. kept tabs on Bergdahl with drones, spies and satellites as behind-the-scenes negotiations played out in fits and starts.

In May 2014, he was handed over to U.S. special forces in a swap for five Taliban detainees at the Guantanamo Bay prison, fueling an emotional U.S. debate about whether Bergdahl was a hero or a deserter.

As critics questioned whether the trade was worth it, President Barack Obama stood with Bergdahl’s parents in the White House Rose Garden and defended the swap. The United States does not “leave our men or women in uniform behind,” Obama declared, regardless of how Bergdahl came to be captured. The Taliban detainees were sent to Qatar.

“Whatever those circumstances may turn out to be, we still get an American soldier back if he’s held in captivity,” Obama said. “Period. Full stop.”

Trump, as a presidential candidate, was unforgiving of Bergdahl, who has been assigned to desk duty at a Texas Army base pending the outcome of his case. At campaign events, Trump declared that Bergdahl “would have been shot” in another era, even pantomiming the pulling of the trigger.

“We’re tired of Sgt. Bergdahl, who’s a traitor, a no-good traitor, who should have been executed,” Trump said at a Las Vegas rally in 2015.

Bergdahl’s guilty plea will follow several pretrial rulings against him that had complicated his defense. Army Col. Jeffery R. Nance, the judge, decided in June that testimony from troops wounded as they searched for him would be allowed during sentencing, a decision that strengthened prosecutors’ leverage to pursue stiffer punishment.

Some of Bergdahl’s fellow soldiers want him held responsible for any harm suffered by those who went looking for him. The judge ruled a Navy SEAL and an Army National Guard sergeant wouldn’t have found themselves in separate firefights if they hadn’t been searching.

The defense separately argued Trump’s scathing criticism unfairly swayed the case. The judge ruled otherwise. Nance wrote in February that Trump’s comments were “disturbing and disappointing” but didn’t constitute unlawful command influence by the soon-to-be commander in chief.

Bergdahl’s lawyers also contended that misbehavior before the enemy, the more serious charge, was legally inappropriate and too severe. They were rebuffed again. The judge said a soldier who leaves his post alone and without authorization should know he could face punishment. The misbehavior charge has rarely been used in recent decades, though there were hundreds of cases during World War II.

Defense attorneys don’t dispute that Bergdahl walked off his base without authorization. Bergdahl himself told a general during a preliminary investigation that he left intending to cause alarm and draw attention to what he saw as problems with his unit. An Army Sanity Board Evaluation concluded he suffered from schizotypal personality disorder.

The defense team has argued that Bergdahl can’t be held responsible for a long chain of events that included decisions by others about how to retrieve him that were far beyond his control.

___

Associated Press writer Jonathan Drew in Raleigh, North Carolina, contributed to this report.