Then-Army Sgt. Bowe Bergdahl leaves a military courthouse on December 22, 2015, in Ft. Bragg, North Carolina.
CNN  — 

A federal judge on Tuesday vacated Bowe Bergdahl’s dishonorable discharge from the US Army, roughly six years after the former soldier was convicted of desertion and misbehavior before the enemy after abandoning his outpost in Afghanistan in 2009.

US District Judge Reggie B. Walton found that the military judge who had ordered the dishonorable discharge had failed to disclose that he had applied to be an immigration judge, a job within the executive branch, during the Trump administration in a possible conflict of interest.

Then-military judge Army Col. Jeffery Nance oversaw the court martial and ruled in November 2017 that Bergdahl would receive a dishonorable discharge from the US Army but avoid prison time. The former soldier’s rank was reduced from sergeant to private, and he was also ordered to pay $10,000 from his salary.

Walton’s 63-page decision vacated all of the judge’s rulings after October 2017, when he applied for the immigration post.

Because the military judge was applying to an executive branch position, “a situation in which he might reasonably be expected to appeal to the president’s expressed interest in the plaintiff’s conviction and punishment,” Walton found that “a reasonable person” could doubt the judge’s ability to remain neutral.

Bergdahl disappeared from his base in Afghanistan in June 2009 and was held in captivity by the Taliban until May 2014. He has said he was tortured and beaten during his five-year captivity, spending months chained to a bed or locked in a cage while his health deteriorated. He has also said that he was completely isolated and told he would be killed and never see his family again.

Released in in a controversial exchange for five Guantanamo Bay detainees, Bergdahl pleaded guilty in October 2017, facing the possibility of life in prison.

While US Army prosecutors had requested a 14-year sentence, Bergdahl’s attorneys had asked for a punishment of dishonorable discharge.

Then-President Donald Trump criticized the decision on Twitter in 2017, calling it a “complete and total disgrace to our Country and to our Military.” Along with calling out Bergdahl as a “traitor” during his 2016 presidential campaign, Trump had also said at the time that he “should be shot” for deserting his post.

CNN’s Dakin Andone, Devon M. Sayers, Holly Yan and Nick Valencia contributed to this report.