A teenager has been spared jail after he spoke about burning down a mosque in an online video and shouted “utterly vile” abuse from the top of a phone box.

Max Ritchings, now 19, posted an Instagram story with a backdrop of news footage of the riots on August 4, following the stabbings of young girls at a dance class in Southport. In the social media post he said: “One more mosque, one more f****** mosque in the area, I will burn the f****** thing down.”

Later that evening Ritchings stood on a phone box near Brighton Pier during Pride weekend wearing a St George’s flag and shouting abuse about Muslims and that foreigners should leave the country.

Ritchings had pleaded guilty to offences of inciting violence online and causing religiously aggravated harassment, when he appeared at Lewes Crown Court on September 11.

Defending, Nicholas Hamblin told the same court on Tuesday that Ritchings has made “substantial changes” in his life in a short period of time since the “grossly unpleasant misguided behaviour”, and was seeking help from a number of organisations.

The court also heard Ritchings recognised that he became “obsessed” with online personalities.

The fatal stabbings at a children's dance class in Southport on 29 July sparked riots in England and Northern Ireland. The unrest was fuelled by misinformation on social media that the suspect was an illegal migrant.

Mr Hamblin said Ritchings was easy to indoctrinate and became involved but has now “clearly detached himself”.

Sentencing him, Judge Christine Laing KC said: “It has to be viewed against the background of unrest … taking place (around) the country at that time and this was your contribution.”

“One of those weighted numbers bringing fear to the streets of the United Kingdom at that time.”

But the judge acknowledged that while he committed “very serious and troubling offences”, Ritchings showed self-reflection and was keen to understand his own mental health difficulties.

Ritchings, of Haywards Heath, was sentenced to 18 months’ imprisonment, suspended for two years.

He was also ordered to complete 300 hours of unpaid work in the community and 18 sessions of rehabilitation activity.