He was originally sentenced to 18 months in detention last year but freed after a high-profile campaign. His conviction was quashed because of the way the initial hearing was handled and a retrial ordered.

The judge advocate general, Jeff Blackett, told Nightingale that his account of how the pistol came to be in his room lacked credibility and the evidence against him was overwhelming.

But he said there were circumstances that allowed the court to suspend the sentence "because of your exceptional character".

The judge also said that "criticism of the prosecution and the army is unmerited and totally without foundation".

"We understand how difficult these proceedings have been for you and your family. However, you have brought much of that anguish upon yourself and your public assertions that you are a scapegoat or the victim of some wider political agenda is absolute nonsense," he said.

"You are simply someone against whom there was a strong prima facie case of serious wrongdoing and, given the dangers to society caused by illegal firearms and their misuse, it was in the public interest to prosecute you.

"You have now had a fair trial before a civilian judge and an independent and impartial board. All of the issues you wished to raise and all the submissions you wished to make have been fully considered and verdicts properly given.

"It would have made no difference had you been tried before a civilian jury – the evidence against you was overwhelming and I have no doubt the verdicts would have been the same."

The judge also criticised commentators and MPs who had criticised the prosecution. "I trust that those who have been so critical of the service prosecuting authority and the court martial process – particularly those who made unfounded and uninformed remarks under the cloak of parliamentary privilege – now realise how inappropriate and wrong their criticisms were."

Blackett, who sat with a five-person board, said if it had not been for a previous court of appeal decision that reduced the original custodial sentence, Nightingale would be going to prison.

"In our opinion, the seriousness of this case does merit an immediate custodial sentence but we feel constrained by the decision of their lordships. In those circumstances, we have decided that the sentences passed should both be suspended for a period of 12 months."

Outside court, Nightingale's wife, Sally, said: "We are disappointed with the sentencing but pleased that Danny will be coming home tonight."

She said they would take advice from their legal team before deciding whether to fight on. "We have got to sit down as a family to discuss the whole issue."

But she said she did not regret fighting the case as they had learned so much about Nightingale's brain injury, sustained when he was taken ill during a jungle challenge.

Nightingale's father, Humphrey, said he was very upset at the judge's criticism of the campaign for the soldier and said it was clear the judge had wanted to give him an immediate custodial sentence. Mr Nightingale continued to insist the gun had not belonged to his son.

The family said Nightingale had been ordered not to speak out again in public about the case – and would face a charge if he did.

The end of the case, for now at least, will come as a huge relief for army prosecutors who have been criticised by Nightingale's supporters for continuing to pursue the former soldier.

It will also be a relief to the SAS, which has been horrified at the glimpses the case has given into its secret workings. Some members have viewed the saga as an attempt by military top brass to rein the regiment in.

The sentence is a bitter blow for the soldier and father-of-two, who faces having to sell his family home to help pay legal costs.

The court martial at Bulford camp had heard that a Glock 9mm pistol and more than 300 rounds of ammunition were found in Nightingale's bedroom in a house shared with a friend and SAS colleague.

Nightingale was brought back to the UK from Afghanistan where he was serving and told civilian police the pistol had been a present from Iraqis he had worked with in 2007. He said he had carelessly stockpiled the ammunition while he worked as a range instructor for the SAS.

At his first court martial last year Nightingale said he could not actually remember being given the pistol, explaining that he had suffered memory loss following a serious illness during an Amazonian jungle challenge. But when it was suggested by the court that he could face five years in prison if he fought the charges he pleaded guilty – and was then shocked when he was handed 18 months in military detention rather than the expected suspended sentence.

His wife, Sally, and legal team launched a campaign to free him. The sentence was reduced and eventually quashed. However, the military prosecutors decided to order a fresh court martial even though Nightingale is being medically discharged early next year.

During the latest hearing, Nightingale claimed the pistol and ammunition must have belonged to his colleague and housemate, who could be identified only as Soldier N. His explanation about how he came by the gun and ammunition was put down to "confabulation" – an unconscious trick of the mind in which gaps are filled in with false memories.

A court martial board took less than five hours to find him guilty of the two charges.

Following his conviction, Nightingale compared his battle with the military authorities to the fight between David and Goliath.

He said his family was close to "financial ruin" because of the case but insisted he did not regret contesting the allegations even if he ended up behind bars. "If I didn't have such a strong family we'd be broken. But I never regret fighting it, not for one second." The court was told that the case had cost Nightingale and his family £120,000.

He refused to comment on whether he believed the military authorities had pursued him because it had been embarrassed by the Nightingale campaign.

Nightingale said he was still proud of his career in the SAS, which he joined in 2001. "This won't taint my military memory. The last few years aren't really part of my military."

After his conviction, Sally Nightingale added: "Continue to support us because he's not guilty and he's not a criminal. He never brought a weapon into the country, he never had a weapon in his possession. We know the truth, the family knows the truth, we know most of the public knows the truth."

The prosecution made it clear during the trial that there were no special exemptions to the SAS when it came to possession of weaponry or ammunition.

"No soldier, no matter what his experience or what unit he is attached to, is above the law," prosecutor Timothy Cray told the court.