FORT BRAGG, N.C. - 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.

The 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 was also overshadowed by President Donald Trump's accusation that Bergdahl is a traitor.

Bergdahl will also lose all benefits, including medical care, afforded to military veterans. He'll also pay a fine of $1,000 a month for the next 10 months.

Gen. Robert Abrams, who convened the court-martial as commander of Army Forces Command, will review the sentence and could potentially reduce, but not increase, the punishment.

The sentence closes a major chapter in what's become 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 former President Barack Obama, who was roundly criticized for his 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 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. They argued that Trump improperly used his position as commander in chief to interfere in the process when he recently referred back to inflammatory statements he made during the presidential campaign. Nance denied the motion, though, saying he felt no pressure to deliver a harsh sentence.

Bergdahl walked away from his combat outpost just before midnight 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 lawyers have said it was a decision he later regretted, 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 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 Sgt. 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 as the war effort in eastern Afghanistan ground 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 working dog. Shannon Allen, the wife of former soldier Mark Allen, said her husband was shot in the head while looking for Bergdahl. 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 Berghdal's defense team would focus on the physical ailments 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 abandoning his unit and enduring extreme conditions and some of the worst torture since the Vietnam War led to 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. His meticulous notes of his cage's design and other methods of restraints 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 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 like 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 on Thursday.

Get the daily newsletter in your inbox each morning with today's top stories.

Recommended for you