A military judge has spared Army Sgt. Bowe Bergdahl for walking off his post in Afghanistan in 2009, slapping him with a dishonorable discharge but no time behind bars.

Bergdahl, who pleaded guilty to desertion and misbehavior before the enemy, faced up to life in prison. Defense attorneys had asked for leniency, citing the five years Bergdahl spent in Taliban captivity, criticism from Donald Trump on the campaign trail, and his mental state.

But prosecutors hoped to prove that Bergdahl endangered his comrades by abandoning his post and called for a 14-year prison sentence.

The judge, Col. Jeffery Nance, reduced Bergdahl's military grade to the lowest level in announcing his sentence. Bergdahl was nervous, clenching both hands as he left the court with his lawyers.

Soldiers, relatives of soldiers, experts, a psychiatrist, and Bergdahl himself testified during the sentencing hearing.

In one of the most powerful testimonies, the wife of a soldier who was shot in the head while searching for Bergdahl spoke of how their family's lives were forever changed. 

"He's lost me as a wife, essentially, because instead of being his wife, I'm his caregiver," said Shannon Allen, whose husband, Master Sgt. Mark Allen, is wheelchair-bound and cannot speak. "I mean, we can't hold hands anymore, unless I pry open his hand and place mine in it." 

Later that day, Bergdahl unexpectedly took the stand. Breaking down, he called abandoning his post a "terrible move" and detailed several unsuccessful escape attempts from his captors. He recalled painful bed sores and said his captors burned the bottoms of his feet. He described having uncontrollable diarrhea, and open sores on his ankles and his head where a blindfold rubbed against his skin. 

Bergdahl walked off from his base in Afghanistan on June 30, 2009, and was captured by the Taliban. He was released in 2014 in a prisoner swap arranged by President Barack Obama. The deal was criticized by Trump and other Republicans. 

While running for president, Trump disparaged Bergdahl, 31, as a "dirty rotten traitor" and called for him to be executed by firing squad or tossed out of a plane without a parachute.