For the first time in eight years, Bowe Bergdahl doesn't face confinement, or the threat of it, after a judge spared the soldier from a prison sentence for endangering his comrades by walking off his post in Afghanistan.

The sentence, which also includes a dishonorable discharge, was quickly condemned by President Donald Trump as a "complete and total disgrace." In the coming months, the final act of the legal drama will play out when Bergdahl's lawyers take his case to a military appeals court to argue that Trump's fiery views of the case merit further concessions — and possibly dismissal of the entire case.

The punitive discharge means the case will automatically be appealed to a higher military court. And a top commander will also review the case and consider arguments for leniency, as is standard in Army legal cases.

Bergdahl walked away from his post in Afghanistan, triggering a search that left some of his comrades severely wounded. He was also captured and held by Taliban allies for five years, and his legal case began when he returned to the U.S.

The judge gave no explanation of how he arrived at his decision, but he reviewed evidence that included Bergdahl's captivity and the wounds suffered by troops who searched for him.

The case was politically divisive. President Barack Obama traded Taliban prisoners to bring Bergdahl back in 2014, drawing sharp Republican criticism. As a presidential candidate, Trump called for the soldier to face stiff punishment. He could have received up to life in prison.

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

Defense lawyer Eugene Fidell told reporters that his client had "looked forward to today for a long time."

Bergdahl "is grateful to everyone who searched for him," especially those who "heroically sustained injuries," Fidell added.

Trump's statement came in a tweet about 90 minutes after the sentencing. "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. 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 his mental health problems. The argument for leniency also cited Trump's harsh campaign-trail criticism.

The dishonorable discharge threatens to deprive Bergdahl of most or all his veterans' benefits, but it also triggers the automatic appeal to a higher military court.

Fidell told reporters that he looks forward to the appeals court review of Trump's campaign statements, which the president appeared to reaffirm on the day Bergdahl pleaded guilty last month. The Friday tweet will also figure into defense arguments.

As a candidate, Trump "made really extraordinary reprehensible comments targeted directly at our client," Fidell told reporters Friday. He said the defense team sees "an extremely strong basis for dismissal of the case."

Earlier in the week, Bergdahl described the brutal conditions of his captivity, including beatings with copper wire, unending bouts of gastrointestinal problems 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. But during closing arguments, they focused on the dangerous search missions that left several service members wounded.

Scores of troops joined in an all-out search for Bergdahl in the weeks after he abandoned his remote post.

Prosecutors cited two missions that resulted in wounds, including a soldier whose hand was shattered by a rocket-propelled grenade and another who suffered a head wound that put him in a wheelchair and rendered him unable to speak. A Navy SEAL suffered a career-ending leg wound.

The judge ruled that those firefights would not have happened if not for Bergdahl.

One of the wounded soldiers, Jonathan Morita of California, called the lack of prison time "unacceptable." Morita, who testified during sentencing, still does not have full use of his dominant hand after he was hit by the RPG, which did not explode.

Referring to the lack of prison time, he said: "It should have maybe not been the life sentence, but it should have been something."

The soldier from Hailey, Idaho, has been working a desk job at a military installation in San Antonio and has not been held in pretrial confinement.


Follow Jonathan Drew at www.twitter.com/jonldrew