SEAN Hogg, who was found guilty in April of raping a 13-year-old girl when he was 17, has had his conviction quashed.
The 22-year-old was convicted of attacking the schoolgirl twice in Dalkeith Country Park in 2018.
He was spared jail by Judge Lord Lake at the High Court in Glasgow in April and was instead given 270 hours of unpaid work, although he said if Hogg was over 25, he would have been sentenced to four or five years behind bars.
The decision not to jail Hogg attracted criticism from Rape Crisis Scotland and other groups.
Hogg - who had been added to the sex offenders' register and put under supervision following his conviction - claimed he was wrongfully convicted of the attacks.
Judges at the Court of Criminal Appeal in Edinburgh have now quashed his conviction after prosecutors admitted “mistakes were made” during his trial.
Hogg's lawyers argued that Lord Lake had misdirected the jury.
At the hearing, the Crown Office accepted this and that part of the verdict should be quashed.
Judge Lady Dorrian said: “There was an insufficiency of evidence for conviction.
“The appeal must succeed.”
After Hogg - from Hamilton in South Lanarkshire - won his appeal, prosecutors decided it was not in the public interest to seek a retrial.
However, they argued that the jury still had enough evidence for Hogg to be convicted of raping the girl on a single occasion.
The Crown Office had planned to challenge the “unduly lenient” sentence, if the appeal against conviction had not succeeded.
In a previous hearing, both the advocate depute and the trial judge were identified as having failed to push for more detail or issue adequate directions to the jury.
Donald Findlay KC, representing Hogg, told that hearing: “There has been a miscarriage of justice.”