Fort Bragg, N.C. • Bowe Bergdahl, the soldier who walked off his post in Afghanistan and triggered a search that left several comrades severely wounded, will serve no prison time, a military judge ruled Friday at the end of the politically divisive case that stirred debate during the president campaign.

President Donald Trump, whose campaign-trail criticism loomed over the case, quickly called the sentence a “disgrace.”

The charges centered on a decision by one soldier that affected many other lives. Bergdahl was captured by the Taliban and held for five years, until President Barack Obama traded Taliban prisoners to bring him back. As a presidential candidate, Trump called for Bergdahl to face stiff punishment. He could have received up to life in prison.

The judge also gave Bergdahl a dishonorable discharge, reduced his Army rank from sergeant to private and ordered him to forfeit pay equal to $1,000 per month for 10 months.

The judge gave no explanation of how he arrived at his decision, but he reviewed evidence including Bergdahl’s time spent in captivity and the wounds suffered by Army searchers.

In court, Bergdahl appeared tense, grimaced and clenched his jaw. His attorneys put their arms around him and one patted him on the back.

His defense lawyer Eugene Fidell told reporters after sentencing that his client “has looked forward to today for a long time.”

Bergdahl “is grateful to everyone who searched for him in 2009, especially those who heroically sustained injuries,” Fidell added.

Trump’s tweet came about 90 minutes after the sentence was announced. “The decision on Sergeant Bergdahl is a complete and total disgrace to our Country and to our Military,” the president wrote.

Bergdahl pleaded guilty last month to desertion and misbehavior before the enemy.

After Bergdahl was released, comrades of a soldier from Utah — Army Staff Sgt. Kurt Curtiss, of Murray — came forward to say that Curtiss and at least five other soldiers had died in searches for Bergdahl.

Curtiss was shot and killed on Aug. 26, 2009, in Afghanistan, nine weeks after Bergdahl’s disappearance.

Curtiss’ father, Bob Curtiss, told The Salt Lake Tribune in 2014 that he was told by the Army that his son was killed in an ambush while searching for a Taliban leader who had taken refuge in a medical clinic.

An Army report about Curtiss’ death, obtained by The Salt Lake Tribune in 2015, references the medical center ambush, but makes no mention of Bergdahl.

Curtiss and Bergdahl were both assigned to the 1st Battalion, 501st Infantry Regiment, 4th Brigade Combat Team, 25th Infantry Division.

The judge had wide leeway in deciding the sentence because Bergdahl made no deal with prosecutors to limit his punishment.

Prosecutors had sought a stiff penalty because of wounds suffered by service members who searched for Bergdahl after he disappeared in 2009.

The defense sought to counter that evidence with testimony about Bergdahl’s suffering as a captive, his contributions to military intelligence and survival training and his mental health problems. The argument for leniency also cited harsh campaign-trail criticism by Trump.

The dishonorable discharge threatens to deprive Bergdahl of most or all his veterans’ benefits, but it also triggers an automatic appeal to a higher military court. Before that, a general who can lower, but not increase, the sentence will also review it.

Fidell told reporters that he looks forward to the appeals court review of Trump’s statements as a candidate, which he appeared to reaffirm on the day Bergdahl pleaded guilty Oct. 16.

As a candidate, Trump “made really extraordinary reprehensible comments targeted directly at our client,” Fidell told reporters Friday, calling the situation “one of the most preposterous states of affairs” in American legal history. He said the defense team sees “an extremely strong basis for dismissal of the case.”

During the multiday sentencing hearing, Bergdahl testified that he was sorry for the wounds suffered by searchers. He also described brutal beatings by his captors, illness brought on by squalid conditions and maddening periods of isolation.

A psychiatrist testified that his decision to leave his post was influenced by a schizophrenia-like condition called schizotypal personality disorder that made it hard to understand the consequences of his actions, as well as post-traumatic stress disorder brought on partly by a difficult childhood.

Prosecutors, who had asked for a sentence of 14 years in prison, did not speak to reporters when they left court. But one of them, Maj. Justin Oshana, said during closing arguments Thursday that Bergdahl “does not have a monopoly on suffering as a result of his choices.”

The sergeant already has a job offer from an animal sanctuary, and a military official who helps design survival training said he would like to use Bergdahl as a part of lectures to service members on how to survive captivity.

The 31-year-old soldier from Hailey, Idaho, was brought home by Obama in 2014 in a swap for five Taliban prisoners held at Guantanamo Bay. He has been stationed at a military installation in San Antonio.