Media playback is unsupported on your device Media caption The campus was put on lockdown as trouble broke out

The University of California at Berkeley was forced to cancel a talk by an editor at right-wing Breitbart News after violent student protests.

Milo Yiannopoulos, 32, is an outspoken supporter of President Donald Trump.

Hundreds of students rallied on Wednesday night. At least one fire was started and riot police used tear gas as the campus was put on lockdown.

Mr Trump later threatened to withdraw federal funds from the university if it "does not allow free speech".

The president suggested it was condoning those who practice "violence on innocent people with a different point of view".

Analysis - Anthony Zurcher, BBC News North America Reporter

You can imagine how it probably went down. Donald Trump woke up in the White House, turned on Fox News and saw images of black-clad anarchists clashing with police on the campus of the University of California - Berkeley.

By 6:13 am ET (11:13 GMT), he had fired off a tweet condemning the university's handling of the incident and threatening to cut off the school's federal funds. (It received $370m (£294m) in federal research grants in 2014-2015).

The violence - which occurred during larger protests against a campus speaking engagement by alt-right writer and provocateur Milo Yiannopoulos - resulted in the university cancelling the event, which prompted Mr Trump's accusations of free speech infringement.

During the 2016 Republican primary campaign, Mr Trump called off one of his own campaign rallies in Chicago because of violent protests outside the venue.

In the days that followed, his team defended the decision as a logical move based on public safety concerns.

That may explain why president seemed a bit uncertain in this recent Twitter fusillade. Unlike many of his all-cap attacks, he ended his threat to withhold federal funds with a question mark, not an exclamation point.

Mr Yiannopoulos later told Fox News that he had been rushed to safety by his security team after protesters began hurling rocks.

"Obviously it's a liberal campus so they hate any libertarians or conservatives who dare to express an opinion on their campuses," he said.

"They particularly don't like me," he added.

Mr Yiannopoulos' comments have been criticised as racist and misogynist.

Last year he was banned from Twitter after leading a campaign against Ghostbusters actress Leslie Jones.

Media playback is unsupported on your device Media caption "Alt-right is unstoppable" - Milo Yiannopoulos

Berkeley College Republicans sponsored Mr Yiannopoulos' visit.

Their spokesman, Pieter Sittler, said they didn't agree with everything he said, but "he gives a voice to repressed conservative thought on American college campuses".

Milo Yiannopoulos: The internet's 'supervillain'

Born Milo Hanrahan in 1984 and raised in a town in Kent, England

Founded the online technology magazine The Kernel in 2011 and sold it 2014

In October 2015, he was employed by the Breitbart News Network, the alt-right media empire until recently headed by senior Trump adviser Steve Bannon

He has sparked controversy with articles such as: "Why do feminists cook up stories about 'misogyny'?"

He describes himself as a "free speech fundamentalist"

When permanently banned from Twitter last July, he said the social media site had "confirmed itself as a safe space for Muslim terrorists and Black Lives Matter extremists, but a no-go zone for conservatives"

He currently has over 468,000 subscribers to his YouTube channel

On his Facebook page, he is described as the "most fabulous supervillain on the internet"

UC Berkeley stressed that it had not invited Mr Yiannopoulos, but had rejected earlier calls to cancel the event.

Protests began peacefully earlier on Wednesday. But demonstrators later broke windows at the hall where the talk was due to be held, threw smoke bombs and started a fire on Sproul Plaza.

Image copyright AP Image caption Mr Yiannopoulos's talk was cancelled after a fire was started on campus

Protest organiser Yvette Felarca defended the demonstration, describing the actions of students as "self-defence".

"We have the right to defend ourselves," she said, adding: "This shutting down Milo Yiannopoulos, and doing whatever's necessary to do that, is our right to self-defence."

But some of the students at the university said the behaviour of a number of demonstrators was "absolutely horrific".

"It's horrible. It's disgusting, what's going on right now. It's one thing to protest someone's right to come here and speak, but it's another thing to create this much amount of destruction and violence," said student Pranav Jandhyala.

Another, Colin Duke, said: "I just came to see if I could get into the Milo event. I support free speech. It's Sproul Plaza, so the birthplace of campus free speech. And it just got shut down by a bunch of people in black cloth."

Image copyright AP Image caption Earlier in the afternoon students had protested peacefully

University spokesman Dan Moulof said the protest had been hijacked by a small number of masked agitators.

"What's really unfortunate tonight is that the violent actions of a very few interfered with the desires of the many to participate in legal and lawful protest," Mr Moulof said.

Image copyright AP Image caption Mr Yiannopoulos wants to "desensitise people to the offence-taking victimhood culture"

Mr Yiannopoulos is a senior editor of Breitbart News, the most-read conservative news website in the US.

Breitbart, which has been accused by some of being a hate site, makes no secret of its close links to Mr Trump.

In November, in an interview with the BBC's James Cook, Mr Yiannopoulos said that despite attempts to silence him, the "alt-right is unstoppable".

"I want to desensitise people to this offence-taking, grievance and victimhood culture, and if the way to respond to outrage culture is to be outrageous - which seems to be working... I'm winning on college campuses to be sure - then so much the better," he said.

Media playback is unsupported on your device Media caption What does 'PC' mean to Democrats?

On Mr Trump's inauguration day last month, a supporter of the president shot a man protesting against a visit by Mr Yiannopoulos to the University of Washington in Seattle.

The gunman was not charged with a crime, after police determined he acted in self-defence.

His Facebook profile indicated that he was also a supporter of the controversial Breitbart editor and the National Rifle Association.

Wednesday's no-show by Mr Yiannopoulos is not his first campus cancellation.

Last November, his old school cancelled a talk he had been due to give.

The Simon Langton Grammar School for Boys in Canterbury, England, said they took the decision partly because of the threat of demonstrations.