Army Sgt. Bowe Bergdahl, the soldier who vanished from his remote base in Afghanistan in 2009, endured five years of brutal militant captivity and was recovered following a controversial prisoner swap with the Taliban, begins a sentencing hearing Monday that could send him to prison for life.

In an Army courtroom at Fort Bragg, N.C., on Oct. 16, Bergdahl, 31, entered a guilty plea to charges of desertion and misbehavior before the enemy. His fate will be decided by a military judge. Bergdahl is hoping the torture he endured as a prisoner, including being caged and beaten, will warrant leniency.

The misbehavior charge, which carries a maximum sentence of life, is a rare accusation, used when troops flee, surrender or endanger fellow service members through disobedience. On the desertion charge, he could receive a maximum sentence of five years. Bergdahl has said he left his base to walk to another U.S. facility, where he hoped to air his grievances about alleged problems in his unit.

The judge, Army Col. Jeffrey R. Nance, will also have to grapple with the defense’s renewed assertion that President Trump’s criticisms of Bergdahl, before and after he took office, have tainted the trial process and should lead to the case’s dismissal. Trump has called Bergdahl a “dirty, rotten traitor.”

Nance said in February that comments by Trump on the campaign trail were “disturbing,” but he concluded they did not amount to unlawful command influence.

The president brought the issue back into focus this month when he declined to comment on the trial but said, “I think people have heard my comments in the past.” In response, the defense wrote last week that “President Trump stands at the pinnacle of an unbroken chain of command that includes key participants in the remaining critical steps of the case.”

Brian Bouffard, a former Navy lawyer who handles courts-martial and civilian cases, said that unlawful command influence is a “showstopping no-no” in military courts and will be an issue for Nance.

The administration appeared to try to get ahead of the matter Friday. "The President expects all military personnel who are involved in any way in the military justice process to exercise their independent professional judgment, consistent with applicable laws and regulations," a White House statement said.

Prosecutors are expected to use testimony from troops who have said they were injured on recovery missions after Bergdahl walked off his outpost in rugged Paktika province. Attempts to find him involved thousands of troops and diverted resources, such as surveillance drones and helicopters, as ground troops scoured the area for weeks.

Nance has ruled that a Navy SEAL and an Army National Guard sergeant were wounded in firefights that probably would not have happened if Bergdahl had not gone missing.

Nance also could take into account Bergdahl’s treatment in Pakistan, where he was held for much of his captivity. An Army physician who testified in the case found that Bergdahl suffered muscular nerve damage in his lower legs, degenerative back damage and a loss of range of motion in his left shoulder that prevents him from lifting heavy objects.

Lt. Gen. Kenneth Dahl, a senior Army officer who interviewed Bergdahl, testified in 2015 that he found Bergdahl “unrealistically idealistic” and that a jail sentence would be inappropriate, given the circumstances of the case. Another doctor concluded that Bergdahl exhibited signs of schizotypal personality disorder, a variant of schizophrenia that has less frequent or intense psychotic episodes.

In addition to confinement, Bergdahl could receive a dishonorable discharge and lose his medical benefits.

Bergdahl, who has been working at Joint Base San Antonio-Fort Sam Houston in Texas, said Trump’s comments were hurtful and expressed doubts he would receive fair treatment, according to an interview published this weekend by Britain’s Sunday Times.

“At least the Taliban were honest enough to say, ‘I’m the guy who’s going to cut your throat,’ ” he told the newspaper. “Here, it could be the guy I pass in the corridor who’s going to sign the paper that sends me away for life.”

President Barack Obama negotiated a prisoner swap in May 2014, handing over five Taliban operatives held at Guantanamo Bay, Cuba, in exchange for Bergdahl. Obama administration officials defended the decision, saying it was in line with long-held military doctrine that troops can never be left behind on the battlefield. But some Republicans said the deal amounted to negotiating with terrorists.

Dan Lamothe contributed to this report.