A man who pleaded guilty to raping a 12-year-old girl has walked free from court.

A judge showed leniency to Daniel Cieslak, 21, of Leith in Edinburgh, by handing him an absolute discharge, meaning he escaped further punishment.

On Friday, he returned to the High Court in Glasgow having earlier pleaded guilty to a rape charge.

The student had sex with the child in July 2015 after meeting her at a taxi queue in Edinburgh city centre.

Cieslak believed she was 16 and he later burst into tears when police revealed her true age.

Lady Scott said she had decided "justice is best served" by taking the "wholly exceptional decision" to give Cieslak an absolute discharge.

She told the court the statutory rape offence had a "very wide scope" with, as a result, a "variation" in sentencing.

The judge continued: "The fact the Lord Advocate decided it was in the public interest in bringing this prosecution does not limit my discretion in deciding the appropriate disposal."

She said the purpose of the offence was to "protect young girls" but added there were "exceptional circumstances" in this case.

The number of factors included Cieslak, and other witnesses, believing the victim was 16 or older.

Lady Scott said the 12-year-old was also an "active participant" in sexual activity and there was no suggestion of "predatory conduct" or grooming.

The judge concluded: "I am satisfied you have been subject to considerable pressure and distress from the burden of this prosecution.

"I do not consider there is any need - or public interest - in punishment.

"To do so would, in my view, be disproportionate given the nature of the criminal culpability here."

Cieslak will not be put on the sex offenders list.

He appeared to be on the verge of tears as he left the dock.

Cieslak was then hugged by a number of weeping women who had joined him at court.

A hearing was last month told how the victim and a teenage friend had been in Edinburgh city centre on July 31, 2015.

In the early hours of the next morning, police were in Princes Street following a report of a missing girl.

The 12 year-old happened to direct officers to the child they were looking for.

Despite the time, prosecutor Kath Harper explained: "Police spoke to (the girl who was raped) but did not note her details as they were not concerned by her age."

The girl and her friend were later in taxi queue when they got talking to Cieslak and his friend.

They all got in a taxi together and headed to a flat in Gorgie, where they had sex.

Days later, the girl told her sister she was "extremely worried" she could be pregnant.

Ms Harper told the court: "She was distressed at this time."

The 12-year-old's GP "encouraged" her to go to the police. It was the girl's sister who reported the incident.

Cieslak later admitted he had sex with the girl but denied it was rape. He said he was told the girl was 16.

Prosecutor Ms Harper said: "When it became clear police were suggesting she was younger, he asked them what age she was.

"When told she was 12 years old, he started to cry and held his head in his hands."

Cieslak had been due to start an architectural technology course at Napier University at the time. He had been studying engineering.

His lawyer David Nicolson said Cielsak "genuinely believed" the girl was years older.