A 28-year-old man who won his appeal against a conviction for attempted murder has been jailed for seven years for possessing a 9mm handgun with intent to endanger life.

Hanees Shabhir was imprisoned for 20 years at Bradford Crown Court in August 2011 for firing at Qaiser Rafique in a dispute between drug dealers.

The Court of Appeal overturned the conviction on the grounds that Rafique, who is behind bars for drug dealing, was a paranoid schizophrenic too afraid to go to court to give evidence.

Yesterday the prosecution accepted Shabhir’s guilty plea to the lesser offence of having a firearm with intent to endanger Rafique’s life.

Judge Jonathan Durham Hall QC ruled that he should be found not guilty of attempted murder.

Shabhir, of Spencer Street, Great Horton, Bradford, had been locked up since September 25 2010, the day after he fired a single shot at Rafique, 26, in Summerville Road in the centre of Bradford.

Prosecutor Stephen Wood said the bullet hit the door of a Lexus car.

Mr Wood said Shabhir, known to Rafique as Hanny, had earlier made threats after the pair fell out over drug dealing.

Rafique’s mental health was affected and he spent time in Lynfield Mount hospital.

On the night of the shooting, Shabhir arranged to meet Rafique and then ran at him. He was dressed all in black and fired the gun from a short distance away.

Shabhir’s barrister, Peter Moulson QC, said a single shot was discharged and no one was hurt.

Shabhir had no previous convictions for violence and intended to move to the south of England to start a new life when he was released from prison. Judge Durham Hall said Shabhir had made excellent progress in custody, earning many qualifications.

He had pleaded guilty to the offence, although Rafique had refused to get on the prison bus to attend court for the attempted murder retrial. The court was told that the gun used by Shabhir had not been recovered.

After the case, a police spokesman said: “One weapon on our streets is one too many and we will continue our robust approach in dealing with those who involve themselves in their use or possession.”