A student has walked free from court after admitting he raped a 12-year-old girl.

Daniel Cieslak, 21, escaped jail after Judge Lady Scott showed leniency and give him an absolute discharge for the offence.

Lady Scott, sitting in the High Court in Glasgow, said Cieslak believed the victim was 16 years old, and the victim had "willingly participated in the sexual intercourse and there was, in fact, consent".

She added that Cieslak would have had a defence if the victim had been a few months older.

Under Scottish law, if a person accused of rape believes the victim was above the age of consent of 16 at the time of the offence, they could mount a defence for raping someone who was underage.

However, this only applies offences where the victim is 13-years-old or over. If the victim is 12-years-old or younger, the rape is a "strict liability" offence, meaning a perpetrator can be charged and found guilty even if they have taken all reasonable care to obey and follow the law.

Lady Scott explained to the High Court in Glasgow: "Although the factual absence of consent is not an ingredient of the offence, it is a material factor for the purposes of sentencing. Here the victim willingly participated in the sexual intercourse and there was, in fact, consent.

"So too, whilst there is no defence to this offence because of strict liability, the fact is that you would have had a defence if the victim had been a few months older.

Cieslak had initially denied rape but admitted to having sex with the girl, who he had met along with her friend in a taxi queue while on a night out in Edinburgh in 2015. The pair later went to a flat where they had sexual intercourse.

Cieslak was said to have broken down in tears when police later told him the victim's real age.

On announcing her decision to give Cieslak an absolute discharge, she said: "You understood from the chat in the taxi that the victim was 16 years old and her friend was 17 years old. The taxi driver had the impression that the victim was about 20 years old. Once at the flat, after some time, you paired off and you and the victim engaged in sexual intercourse. She left the next morning. She had no concerns and there was no suggestion of her being distressed."

Lady Scott added that police officers searching for missing girls had stopped the girl and her friend, but did not take their details or take them off the street as the officers believed they were over 16.

In addition, the girl told Cieslak she was 16.

Prosecutor Miss 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."

The court heard in a previous hearing, the incident only came to light when the girl, who was worried that she might be pregnant confided to her sister, who informed the police what happened.

Under Scottish law, an 'absolute discharge' ruling means that no conviction is recorded for the defendant and no special obligations are placed on that person, despite them being found guilty.