A man has walked free from court after pleading guilty to the rape of a 12-year-old girl.

Lady Scott took the "wholly exceptional" decision to grant Daniel Cieslak an absolute discharge at the High Court in Glasgow on Friday.

Cieslak, 21, met the victim and her friend, aged 12 and 13, in a taxi queue in Edinburgh after a night out in the summer of 2015 and went back to a party with them thinking they were 16 and 17, a statement on the Judiciary of Scotland website said.

He was 19 at the time.

Lady Scott said: "You understood from 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."

Police officers who had spoken to the victim earlier in the night in relation to another matter also had no concerns over her age, Lady Scott said in her order.

The judge said Cieslak was culpable under "strict liability", where victims under 13 are deemed by law to be incapable of consent.

But the judge said there were "a number of exceptional circumstances" which applied.

She said: "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.

"The statutory offence for girls aged over 13 to 16 years provides for a defence based on reasonable grounds of belief by the accused that the victim was above the age of consent.

"It is clear from the agreed facts presented to me that the Crown would have been unlikely to, or unable to, exclude such a defence and they do not dispute this. Accordingly, it is very unlikely the Crown could prove a crime had the victim been over 13 years of age."

Cieslak became distressed when he was told the age of the victim by police officers and has dropped out of a college course, Lady Scott said.

Taking into account that all witnesses on the night thought the victim was over 16, that Cieslak was told she was 16 and with no signs of distress, Lady Scott said: "Your criminal culpability here is wholly restricted to the application of strict liability within this offence.

"That is in marked distinction to other reported cases under this statutory provision, which have involved conduct involving assault or recklessness or force, or the absence of consent or have resulted in distress to the victim - all of which are factors which raise the need for punishment.

"In addition, there is no suggestion here of predatory conduct or grooming or manipulation or deception.

"I do not consider there is any need for, or public interest in, punishment. To do so would in my view be disproportionate given the nature of the criminal culpability here.

"Nor do I consider there is any basis for, or real public interest in, requiring your notification under the Sexual Offences Act 2003.

"Considering all of these factors I have reached the conclusion that justice is best served in this case by taking the wholly exceptional decision not to sentence you and instead I discharge you absolutely.

"As a result, the requirement of any notification does not arise under the relevant statutory provisions."