London (CNN) A far-right extremist has been locked up in a UK hospital indefinitely after setting fire to a synagogue in the city of Exeter, Press Association (PA) reports.

Tristan Morgan, whom one prosecutor described as having "deep-rooted anti-Semitic belief," was sectioned under the Mental Health Act at London's Old Bailey on Friday, after the court heard that he was having a psychotic episode during the time of the attack.

According to PA, Morgan admitted to arson, to having a white supremacist handbook and to encouraging terrorism by publishing a song titled, 'White Man,' to Soundcloud.

CCTV footage recovered at the scene was shared by local police. It showed Morgan using a small ax to break a window of the Exeter Synagogue, and pouring a liquid inside on July 21, 2018—on a day commemorating the Holocaust.

The 52-year-old set the liquid alight, but it backfired. CCTV footage showed him being engulfed in a sudden jet of fire from the synagogue, which blew off his cap and singed his hair. The flames also left him with burns on his hands and forehead, PA reported.

"The footage, which was played in open court, shows the level of planning, determination and intent by Morgan, whom the wider evidence clearly showed held abhorrent extreme right-wing, anti-Semitic, and white supremacist views," Police Superintendent Matt Lawler said in a statement.

"Morgan is clearly very unwell and following multiple detailed medical assessments it is clear that a hospital order is appropriate, " he added.

The court heard that firefighters found a "severe" fire in a room containing a gas boiler, which could have exploded, in an attack described as "devastating" to the whole Jewish community, PA reported.

'Desire to do harm'

After lighting the fire, Morgan was spotted by witnesses seeming to laugh as he walked away from the burning building, while holding a petrol can.

"He appeared to be laughing, while trying to flatten his hair," prosecutor Alistair Richardson said Friday, according to PA.

One witness described Morgan's hair looking "whooshed up," he said.

When Morgan was arrested by police, smelling of petrol, he said: "Please tell me that synagogue is burning to the groundif not, it's poor preparation," PA reported.

The prosecutor Richardson said that Morgan harbored "deep-rooted anti-Semitic belief, embodied in a desire to do harm to the Jewish community and an obsession with abhorrent anti-Semitic material."

"It is only by sheer chance that the Synagogue was empty and indeed that Morgan himself sustained only minor burns," Police Superintendent Lawler said in a statement.

The synagogue, which was built in 1763, is "a focal point for the Jewish identity of many Jews living in the South West [of England]," its website said.

According to PA, repairs to the room where the fire occurred cost more than £23,000 ($28,804).