In only the second case of its kind, a man jailed for murder has had his conviction quashed because of failures in the case prepared by his defence team, which included the leading QC, Donald Findlay.
John Hemphill, 35, was found guilty of the murder of his former girlfriend Sarah Jane Cannon in 1995 and has been in prison for almost six years.
Mr Hemphill had denied the charges claiming he arrived on the scene after Miss Cannon was shot and cradled her in his arms as she was dying.
But in his appeal he accused his defence team of failing to call their own expert witnesses to give evidence.
Lord Cameron, who heard the appeal, with Lord Milligan and Lord McCluskey, said they had reached the view that Mr Hemphill had suffered a miscarriage of justice because he was denied a fair trial.
Lord Cameron said: "The failure of investigation and preparation of the defence case was so fundamental in the circumstances of this case that it affected the conduct of his defence to such an extent that he did not have the fair trial he to which he was entitled."
The ground for appeal that an accused was deprived of his right to a fair trial because of the conduct of his counsel or solicitor was only established in the Scottish courts by a five-judge appeal bench in 1995.
Members of Mr Hemphill's family broke into cheers at the Court of Criminal Appeal in Edinburgh after the judges said his conviction would be quashed.
The judges agreed to grant authority to the Crown to bring a new prosecution if it chooses to do so.
Miss Cannon, 20, was shot twice in the head and once in the mouth in the killing at her home in Port Glasgow, Renfrewshire.
After Mr Hemphill was convicted he turned to the appeal court claiming that there was "inadequate preparation and conduct" of his defence case which resulted in important and significant witnesses, and forensic and medical evidence not being produced at his trial.
The Crown had relied heavily on blood spots on his clothes and evidence from a pathologist, Dr Marie Cassidy, that after being shot twice in the head the victim would have stopped breathing within seconds.
Mr Hemphill told police that when he held the dying woman she was still breathing and there was blood coming out of her mouth.
He accused his defence lawyers of failing to call two of their own expert witnesses to give evidence.
They had previously indicated that an attempt by the victim to speak or cough could have caused the blood spots on Mr Hemphill's clothes and said it was well documented that catastrophic head injuries did not necessarily produce instant death.
He also said they failed to take statements from the Crown's expert witnesses, particularly Dr Cassidy and to call for other pathologists' opinions on the timing of the death.
They also failed to take statements from witnesses at the scene as to whether they had seen Miss Cannon breathing.
Mr Hemphill's new counsel, Margaret Scott, told the appeal judges that the conduct of the trial counsel and the original defence solicitors had deprived Mr Hemphill of his right to a fair trial.
She said important forensic and pathological evidence crucial to his defence that he was not present when the fatal shots were fired had not been investigated or lead at the trial.
Lord Cameron said there was "a substantial failure on the part of those instructed for the defence properly to consider and investigate the real basis of a material part of the case for the Crown".