A would-be sex offender was foiled by a brave 14-year-old schoolboy who kneed him in the groin after being confronted in a public toilet.

Peter Rogers slid a note under a door of a cubicle in the conveniences at Barnstaple bus station after spying on the boy through a hole in the wall.

He asked the boy to take part in a sex act and then stood in the boy’s way as he tried to flee from the situation.

The child responded by kneeing him in the groin and retreating back into the cubicle until Rogers left.

He then followed him out and used his phone to take a video clip of the 58-year-old as he left the bus station.

The schoolboy was in uniform when he went into the toilets and Rogers would have known that he was a child, Exeter Crown Court was told.

Rogers, of Barnstaple, admitted inciting a child to engage in sexual activity and was curfewed for six weeks and sent on a sex offenders programme under a three year community order with 20 days of rehabilitation activities.

He was also made subject of a sexual harm prevention order, which bans unsupervised contact with boys, and put on the sex offenders register by Judge David Evans at Exeter Crown Court.

The judge told him he had caused alarm and psychological distress to the boy, who was confused at finding himself in an unprecedented situation.

He said: “When he came out of the cubicle, you pushed him against the wall and he had to knee you between the legs to get you to desist. Later, he had the presence of mind to take some short footage on his phone and raise the alarm immediately.”

Miss Heather Hope, prosecuting, said the incident happened on July 1 last year when the boy went to use the toilets after seeing off friends at the bus station.

He was in the cubicle when Rogers put two notes under the wall. The first asked the boy to show him his genitals and the second offered to perform oral sex on him.

The boy noticed a hole in the cubicle wall about the size of a 20 pence piece which he blocked with his hand. He tried to leave but Rogers stood outside the door and stopped him and the boy kneed him in the groin.

Police were able to identify Rogers because he spent much of his time at the bus station cafe, where staff noticed his lengthy visits to the public toilets.

Mr Richard Crabb, defending, said there had been no actual sexual contact. He said Rogers has been assessed as eligible to take part in a sex offenders’ treatment programme.