Army Sgt. Bowe Bergdahl was sentenced to a dishonorable discharge, avoiding prison time, on Nov. 3. Bergdahl, who the Taliban held hostage for five years, pleaded guilty in October to charges of desertion and misbehavior before the enemy. (The Washington Post)

Sgt. Bowe Bergdahl, who in 2009 walked off a U.S. military outpost in eastern Afghanistan and spent the next five years in enemy captivity, was sentenced Friday to a dishonorable discharge from the Army but will avoid prison time.

Bergdahl, 31, pleaded guilty in October to charges of desertion and misbehavior before the enemy and had faced a maximum life sentence. As the judge, Army Col. Jeffery R. Nance, prepared to read his sentence, Bergdahl appeared shaken, clenching his jaw as he had done during other tense moments throughout the proceedings.

It was unclear how Nance arrived at his decision. The judge promptly left the courtroom after delivering the announcement, making no additional statements. A member of Bergdahl’s defense team wept.

Bergdahl’s case sparked ferocious debate over his actions and the controversial prisoner exchange that led to his release in 2014, challenging the military’s bedrock principle of never leaving a soldier behind.

It also was overshadowed by President Trump’s accusation that Bergdahl is a traitor who should be executed. Bergdahl’s defense seized on those remarks, arguing they compromised his right to a fair hearing. Nance indicated earlier this week that Trump’s statements could result in a less severe sentence.

Sgt. Bowe Bergdahl leaves the courthouse after the seventh day of sentencing proceedings in his court-martial at Fort Bragg, N.C., on Thursday. (Jonathan Drake/Reuters)

Writing Friday on Twitter, Trump called the judge’s decision “a complete disgrace to our Country and to our Military.”

Eugene Fidell, Bergdahl’s lead attorney, indicated before Trump’s tweet that the president’s pattern of incendiary remarks constituted grounds for an appellate court to dismiss the sentence entirely.

As a consequence of his dishonorable discharge, Bergdahl will lose all benefits, including medical care, afforded to military veterans. He will also forfeit $1,000 a month for the next 10 months. His rank will be reduced from sergeant to private.

Gen. Robert Abrams, who convened Bergdahl’s court-martial as commander of Army Forces Command, will review the sentence before it goes to an appellate court, a process that could take months.

Fidell said in a written statement that Bergdahl is grateful to those who searched for him during his captivity and to those who helped secure his release. He also excoriated Trump for what he called an “unprincipled effort to stoke a lynchmob atmosphere” during the presidential campaign.

“Every American,” Fidell’s statement said, “should be offended by his assault on the fair administration of justice and disdain for basic constitutional rights.”

Bergdahl’s legal team intends to pursue the military’s Prisoner of War Medal for him.

The sentence closes a major chapter in what became an eight-year odyssey. Bergdahl, the sole U.S. service member to be captured in Afghanistan, became a political lightning rod across two administrations. The episode drew in Trump and President Barack Obama, who was roundly criticized for holding a Rose Garden ceremony to celebrate Bergdahl’s return even as details of the soldier’s voluntary abandonment had begun to circulate.

Trump said on the campaign trail that Bergdahl was a “dirty, rotten traitor” who should be executed. Bergdahl’s sentencing hearing began Oct. 23 with a motion from Bergdahl’s attorneys to dismiss the case on grounds that Trump improperly used his position as commander in chief to interfere in the process. Trump recently referred to his inflammatory statements.

Nance denied the motion, saying he felt no pressure to deliver a harsh sentence.

Bergdahl walked away from his combat outpost just before midnight on June 29, 2009, in what an Army investigation determined was an attempt to cause a crisis and draw attention to concerns that Bergdahl had about his leaders.

While Bergdahl and his attorneys have said it was a decision he later regretted, a prosecutor, Maj. Justin Oshana, said Thursday that “it wasn’t a mistake — it was a crime.”

Bergdahl was captured within hours by armed Taliban fighters on motorcycles and turned over to the Haqqani network, a group in Pakistan that tortured him on and off for years. His release was secured as part of a controversial prisoner exchange, initiated by the Obama administration in 2014, in which five Taliban militants were swapped for the U.S. soldier.

Bergdahl’s attorneys maintained that psychological conditions, which according to expert testimony impair his reasoning skills and existed before his military service, led to Bergdahl’s fateful actions and that he should be granted leniency. Additionally, five years of brutal captivity was sufficient punishment, his attorneys said.

They did not dispute that their client committed serious offenses.

Capt. Nina Banks, a member of the defense counsel, told Nance a dishonorable discharge from the Army was a suitable punishment instead.

“Justice is not rescuing Sergeant Bergdahl from his Taliban captors, in the cage where he was for years, only to place him in a cell,” she said Thursday.

The prosecution has said Bergdahl’s decisions contributed to grim injuries, with the war effort in eastern Afghanistan grinding to halt so that thousands of U.S. and Afghan troops, charged with rolling back Taliban influence and securing polling stations for upcoming elections, could instead look for Bergdahl. But the trail quickly grew cold. Later they would learn he had been spirited away to Pakistan.

James Hatch, a former Navy SEAL, said in court that he was shot in the leg during a rescue mission and saw a militant kill a military dog. Shannon Allen, the wife of former soldier Mark Allen, said her husband was shot in the head while looking for Bergdahl. Mark Allen is now almost totally paralyzed and cannot talk, walk or care for himself, she said in emotional testimony for the prosecution.

Oshana keyed on Allen’s injuries in anticipation that Bergdahl’s defense team would focus on the physical ailments that Bergdahl suffered while in captivity, including nerve damage and a shoulder injury.

“Mark Allen is in pain all of the time,” Oshana said. “The only difference is that Sergeant Bergdahl can tell someone where his pain is. Master Sergeant Allen cannot.”

Yet in a strange way, Bergdahl’s experience in captivity, enduring extreme conditions and some of the worst torture inflicted on an American service member since the Vietnam War, resulted in positive outcomes for the U.S. military and intelligence community.

Two experts who debriefed Bergdahl testified that his detailed recollections of militant procedures and observations of the prisoner network system was a “gold mine” of intelligence that greatly enhanced understanding of how the Haqqanis operate. Bergdahl’s meticulous notes detailing his cage design and the other restraint methods his captors used helped contribute to U.S. doctrine and procedures of escaping and surviving enemy captivity, one expert said.

Lt. Gen. Kenneth Dahl, a senior Army officer who interviewed Bergdahl, testified in 2015 that he found Bergdahl “unrealistically idealistic” and believed that a jail sentence would be inappropriate, given the circumstances of the case. A military doctor determined that Bergdahl, who had previously washed out of the Coast Guard, exhibited symptoms of schizotypal personality disorder, considered a variant of schizophrenia that has less frequent or intense psychotic episodes.

Bergdahl’s punishment will have an effect long after his sentence is complete. Veterans with an honorable discharge gain access to a suite of resources such as care and education benefits from the Department of Veterans Affairs.

That is not true in Bergdahl’s case. A dishonorable discharge from the Army is socially stigmatizing, Nance told Bergdahl following the defense’s closing remarks Thursday.

A former soldier who served in Bergdahl’s unit when he abandoned his base told The Washington Post it was important for soldiers who served on the deployment, many with complicated feelings about Bergdahl, to see the sentence handed down.

“I’m glad it’s over with. The ordeal prevented people from moving on. So maybe now they can,” the former soldier said, speaking on the condition of anonymity to avoid conflicts with his current employer.

But the former soldier also noted a central issue in the case: Bergdahl’s mental health at the time of his enlistment, evident when he washed out of the Coast Guard.

“He shouldn’t have been in the Army anyway,” the former soldier said. “A lot of things went wrong along the way.”

Dan Lamothe contributed to this report.