Updated

Army Sgt. Bowe Bergdahl, who was held captive in Afghanistan for several years after leaving his station, was dishonorably discharged Friday.

Bergdahl had pleaded guilty to desertion and misbehavior before the enemy. A judge spared him jail time and dishonorably discharged him. He faced up to life in prison for his charges; prosecutors wanted a 14-year punishment.

He will also have to pay a $1,000 fine every month for 10 months.

Bergdahl was shaking and appeared emotional as the verdict was read.

“He’s certainly glad this is over,” Bergdahl’s attorney, Eugene Fidell, told reporters after the sentencing.

Fidell also said he will appeal the decision. Beacuse of President Trump's comments about the case, Fidell said he still believes the case should be dismissed.

Bergdahl’s story left the nation debating for years about whether he is a hero or traitor, as well as the importance of the long-held American commitment not to leave troops behind. Former President Barack Obama defended swapping prisoners at Guantanamo Bay for Bergdahl’s release in 2014 while Trump said Bergdahl should “face the death penalty.”

Why was Bergdahl on trial?

Then 23, Bergdahl went missing from his remote infantry station near the Pakistan border in June 2009. His disappearance launched a massive search operation.

Bergdahl was quickly captured by the Taliban after leaving his post. The U.S. tracked him for several years before successfully negotiating his release in 2014.

The U.S. does not "leave our men or women in uniform behind," Obama said, regardless of how Bergdahl came to be captured.

bergdahl_wh

Army Sgt. Bowe Bergdahl pleaded guilty to desertion and misbehavior before the enemy. (Reuters/Jonathan Ernst)

Bergdahl has said that he left his post and intended to alert people about problems he perceived within his unit. Investigators said Bergdahl suffered from schizotypal personality disorder when he left his station.

The Army charged him with desertion and misbehavior before the enemy in 2015.

What could have happened?

Bergdahl faced up to five years in prison on the desertion charge. But he could also have been sentenced to life in prison for the misbehavior charge.

Bergdahl elected to be tried by a judge, not a panel of military officers, in August.

What has Trump said?

Trump has been a vocal critic of Bergdahl and the Obama administration’s decision to exchange five prisoners in Guantanamo Bay for his release in May 2014.

BERGDAHL HAD PSYCHIATRIC DISORDER WHEN HE LEFT POST, DOCUMENTS SAY

"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.

On Twitter, Trump has also said Bergdahl should face the death penalty and repeatedly referred to him as a “traitor.”

Trump’s past comments almost derailed the case against Bergdahl as a judge had to decide if they would prevent him from having a fair trial.

Ultimately, Army Col. Jeffery Nance ruled that he would only consider Trump’s comments as a mitigating factor in Bergdahl’s sentencing – not an aggravating factor.

What happened during the trial?

Bergdahl unexpectedly testified during his sentencing hearing and emotionally apologized to his fellow service members who had been injured as they attempted to rescue him.

"I would like everyone who searched for me to know it was never my intention for anyone to be hurt, and I never expected that to happen," he said. "My words alone can't take away their pain."

The wife of National Guard Master Sgt. Mark Allen – who is confined to a wheelchair and unable to speak after being shot in the head while searching for Bergdahl – also gave an emotional testimony.

Shannon Allen said her husband is unable to play with their children and “can’t even hold hands anymore.”

“He’s not able to reach out for her or talk to her,” Shannon Allen said of her daughter, who was just an infant when her husband was injured. “He’s never had the chance to really play with her or help coach her sports or ask about her day.”

Fox News' Terace Garnier and The Associated Press contributed to this report.