An “inspirational teacher” at a primary school in Hampstead has been spared jail after sexually abusing a nine-year-old girl on a school trip.

The man, who cannot be named for legal reasons, walked free from court with just a community order on Thursday.

The prosecution said he had carried out “fairly sophisticated grooming” on the little girl before twice touching her intimately on a school trip this year.

Doctors said the teacher had been suffering from “clinical depression” and had “obsessional personality traits”.

Sentencing him, Judge Donne QC said it was “an exceptional case which justified diversion from the guidelines” after 21 parents wrote letters in support of the teacher.

Judge Donne said: “It would have been my preference to have marked this offence with a custodial sentence, but it is clear that treatment is what is needed here to enable you to come to terms with what you have done.”

Harrow Crown Court heard the long-serving teacher had asked if the girl was ticklish before the school trip. The nine-year-old confided that her feet were ticklish and that she was also ticklish in another place.

Prosecutor Caroline Hughes said that during the trip, the little girl asked if the teacher wanted to know where else she was ticklish.

At first the teacher said he did not, but then he ran his hand over her leg and stroked her intimately through her clothes, the court heard.

He pulled back in shock at what he had done, but when the pupil pulled down her shorts and underwear and pointed out the spot at the top of her thigh, the teacher touched her naked skin for around three seconds.

Ms Hughes said: “At this point he started freaking out, saying he was going to prison. She [the girl] could not understand and tried to reassure him and said she was not going to tell anyone. He built up a friendship with her to the extent that she really didn’t want to tell anyone what had happened.”

Parents of children on the trip sat in the public gallery to support the teacher, who pleaded guilty last month to one count of sexual activity with a girl under the age of 13.

One parent called the teacher a “stalwart” and said: “This was so completely out of character that I cannot believe I am standing here even to discuss it.”

The teacher was sentenced to a three-year community order to undergo community sex offender group work. He was banned from unsupervised contact with girls aged 16 or under, made to sign the sex offenders’ register for three years and ordered to pay �1,000 in costs.