A man who posted anti-Muslim rants online before setting fire to a mosque in Fort Pierce, Florida, on the anniversary of the attacks of Sept. 11, 2001, now faces 30 years in prison.

Joseph Michael Schreiber, 32, entered a “no contest” plea yesterday in state court after being charged with arson with a hate crime enhancement.

The fire heavily damaged the Islamic Center of Fort Pierce, where Omar Mateen, who carried out a mass shooting at an Orlando nightclub, had worshipped. The damage was so extensive that mosque leaders say they will move to a new location.

The crime came during last year’s presidential campaign, as Muslims across the United States faced a “hostile political climate” and were increasingly targeted by threats.

Surveillance video, which ultimately led to Schreiber’s arrest, showed a man carrying a bottle of liquid and a handful of paper just moments before the fire broke out.

Before the arson, Schreiber, who is Jewish, posted on Facebook that “all Islam is radical” and that all Muslims should be treated as terrorists and criminals.

Prosecutor Steve Gosnell said Schreiber confessed to setting the fire, telling detectives that he believed Muslims “are trying to infiltrate our government” and that “the teaching of Islam should be completely, completely illegal,” The Associated Press reported.

In court, Schreiber read a statement claiming the hate did not drive him to start the fire, but rather anxiety. He said he feared another attack like those of 9-11, the Boston Marathon bombing or the Pulse nightclub shooting last June in Orlando.

“My message is this to all the Muslim communities on the face of the Earth — make peace with America and make peace with Israel and stop the killings, stop the attacks,” Schreiber said in court, according to various media accounts.

He then turned to mosque member Mohammad Malik, seated in the courtroom, and apologized.

After the hearing, Malik told reporters that he believes Schreiber was “misled by fear-mongering (and) false information” being spread by Islamophobes. A “bright spot” that resulted from the arson attack, Malik said, is that local Jewish and Islamic communities are now communicating.

“In the Islamic faith and in all faiths, we believe that God is merciful. And just as we want to be forgiven by him, we should also forgive,” Malik told reporters.