President Trump tweeted early Thursday that if schools like University of California, Berkeley, do not allow free speech, it may cost them federal funding.

The tweet was in response to violent protests that were in response to a planned talk on campus Wednesday by Milo Yiannopoulos, a controversial Breitbart News editor. The talk was canceled due to the protests.

The decision was made two hours before the event because a crowd of more than 1,500 had gathered outside the venue, the university said in a statement.

"Of paramount importance this evening was the campus's commitment to ensure the safety and security of those attending the event, the speaker, those who came to engage in lawful protest, as well as members of the public and the Berkeley campus community," it said.

The 32-year-old right-wing provocateur is a vocal supporter of President Donald Trump and a self-proclaimed internet troll whose comments have been criticized as racist, misogynist, anti-Muslim and white supremacist. He was banned from Twitter after leading a harassment campaign against "Ghostbusters" actress Leslie Jones.

Yiannopoulos' visit to Berkeley was sponsored by the campus Republican club. The university has stressed it did not invite him and does not endorse his ideas but is committed to free speech and rejected calls to cancel the event.

Hundreds of peaceful demonstrators carrying signs that read "Hate Speech Is Not Free Speech" had been protesting for hours before the event.

In the evening, a small group dressed in black and in hooded sweatshirts used metal barricades to break windows, threw smoke bombs and flares, used a diesel generator to start a large bonfire outside the building.

"This was a group of agitators who were masked up, throwing rocks, commercial grade fireworks and Molotov cocktails at officers," said UC Berkeley Police Chief Margo Bennet.