Image copyright Reuters Image caption Bergdahl was facing up to life in prison after he pleaded guilty last month to desertion

US Army soldier Bowe Bergdahl will be spared prison time after he was found guilty of deserting his Afghan outpost in 2009, a military judge has ruled.

Under the sentence in his court martial, the 31-year-old sergeant will be dishonourably discharged, reduced to private in rank and lose pay.

Prosecutors had argued Bergdahl should spend 14 years behind bars for endangering US troops in Afghanistan.

He spent five years in Taliban captivity after abandoning his post.

US President Donald Trump tweeted that the sentence was a "total disgrace".

He has repeatedly called Bergdahl "a traitor" and criticised the Obama-era prisoner exchange with the Taliban that led to the American soldier's release.

The judge, Army Col Jeffery R Nance, considered the president's attacks as a mitigating factor in sentencing Bergdahl, whose lawyers argued he could not receive a fair trial because of the comments.

On Friday, the judge said the Idaho native must forfeit pay equal to $1,000 (£765) per month for 10 months.

Bergdahl had been facing up to life in prison after he pleaded guilty last month to desertion and misbehaviour before the enemy.

His lawyer Eugene Fidell told reporters: "He has lost nearly a decade of his life.

He said Bergdahl is glad his "terrible ordeal" is now over.

Major Justin Oshana, for the prosecution, told the sentencing hearing that other US troops were injured in the hunt for Bergdahl.

But Captain Nina Banks, for the defence, said that when he deserted, Bergdahl had not yet been diagnosed with schizotypal personality disorder, which includes grandiose thinking.

The soldier said he had walked away from his outpost in Paktika province to report problems in his unit.

The military investigator who interrogated Bergdahl following his return from the US had told officials he did not believe he deserved further punishment.

He said Bergdahl had suffered the worst case of prisoner abuse against a US soldier in captivity since the Vietnam War.

On Monday, Bergdahl took the stand to apologise to the troops who were wounded in the search for him.

Image copyright Reuters Image caption Shannon Allen's husband was shot in the head in the search for Bergdahl

"I made a horrible mistake," he said in the courtroom at Fort Bragg, North Carolina. "Saying I'm sorry is not enough."

Master Sergeant Mark Allen was shot in the head during a July 2009 mission to find Bergdahl.

His wife, Shannon Allen, who was a witness for the prosecution this week, described the impact of her husband's debilitating brain injury.

"Instead of being his wife, I'm his caregiver," she said in an emotional testimony.

"Which doesn't mean I love him any less, but it's a very different dynamic.

"We can't even hold hands anymore without me prying open his hand and putting mine in."

Bergdahl testified that his Taliban captors had locked him in a cage after he briefly escaped.

He said he received little food, water or sleep and was forced to watch beheading videos.

Bergdahl was freed in a politically contentious 2014 Taliban prisoner swap brokered by former President Barack Obama's administration.