A protest at UC Berkeley over a scheduled appearance by right-wing provocateur Milo Yiannopoulos turned fiery and violent Wednesday night, prompting police to cancel the event and hustle the Breitbart News editor off campus.

But even after the event’s cancellation, hundreds of protesters spilled off campus into the city streets, where the violence continued as they confronted drivers, engaged in fights, smashed storefront windows and set fires.

Protesters decried President Trump’s policies as much as they did the visit by Yiannopoulos, a gay conservative who has been making the rounds at college campuses across the country with his “Dangerous Faggot” talks, specializing in remarks meant to insult, offend and disgust liberals who disagree with his ideas.

Milo speaks: ‘The Left is absolutely terrified of free speech’

The trouble began around 6 p.m., two hours before Yiannopoulos was to begin his speech inside the student union building on Sproul Plaza. Protesters outside the building began throwing fireworks and pulling down the metal barricades police set up to keep protesters from rushing inside. Windows were smashed and fires were set outside the building as masked protesters stormed it. Police quickly evacuated Yiannopoulos for his own safety.

Berkeley police said five people were injured and some people, including a man who said he had hoped to see Yiannopoulos speak, were seen with their faces bloodied. There were no arrests.

Police said protesters threw bricks and fireworks at police officers. University police locked down all buildings and told people inside them to shelter in place, and later fired pepper balls and paint balls into the crowd of protesters who defied orders to leave the area. Police called in support from nine of the 10 UC campuses and the Oakland Police Department and Alameda County sheriffs department.

“This is what tolerance looks like at UC Berkeley,” Mike Wright of Berkeley College Republicans, the group that invited Yiannopoulos to the campus, said outside the student union building as smoke bombs went off around him.

As he spoke, someone threw a glass bottle of red paint at him. The bottle shattered and splattered paint on his clothing. “It’s sad,” he said.

On Berkeley’s city streets, protesters took their rage against construction sites and businesses, smashing windows at banks and stores. They also confronted motorists, and at one point a driver sped off with a protester on the car hood.

University officials had earlier rejected requests to cancel Yiannopoulos’ appearance. In a letter to the campus community last week, Chancellor Nicholas Dirks said, “The U.S. Constitution prohibits UC Berkeley, as a public institution, from banning expression based on its content or viewpoints, even when those viewpoints are hateful or discriminatory.”

Protesters argued that what Yiannopoulos specializes in is hate speech, and that it didn’t deserve to be protected.

“It’s not a question of free speech,” a protester said via megaphone, riling up the hundreds of protesters. “It’s about real human beings.”

Yiannopoulos’ appearances at some universities have resulted in violent confrontations between protesters and his supporters. Some private universities have barred him, and Twitter banned him in July for repeatedly breaking harassment and abuse policies.

Berkeley College Republicans said all 500 tickets had been sold for Yiannopoulos’ scheduled appearance in Pauley Ballroom in the student union building. Yiannopoulos was expected to use the event to kick off a campaign against “sanctuary campuses” that have vowed to protect students in the country illegally as President Trump cracks down on illegal immigration.

Campus police had been hoping to avoid a repeat of the chaos at UC Davis on Jan. 13, when protesters overwhelmed their barricades and shut down Yiannopoulos’ speech.

In an interview with Fox News after Wednesday’s cancellation, the 32-year-old Yiannopoulos — a self-described “libertarian, gay, Trump-supporting provocateur” — said college campuses are places where “you should be able to engage with different ideas.”

Those who attend his appearances, he said, include people who “don’t necessarily agree with me but just want to hear the other side. They were prevented from doing so this evening by violence from the left — the left that is terrified of anyone who they think might be persuasive or might be interesting or might take people with them.”

But UC Berkeley sophomore Jonathan Gow, 19, rejected Yiannopoulos’ insistence that free speech took a hit.

“The whole reason we’re here is for free speech,” Gow said. “Milo’s hate speech is not allowed here. When it’s hate speech, our free speech is to shut him down.”

Three lines of zip-tied metal fencing separated the crowd of protesters from campus police officers who had secured the building where Yiannopoulos was supposed to speak. He had arrived earlier, escorted by security, and had been waiting inside the student union building when the protests erupted.

The protest turned violent around 6 p.m. when dozens of masked anarchists, dressed in black and wearing backpacks, emerged from the otherwise peaceful crowd.

As “Milo has got to go” chants broke out, they struck: in small groups, at first — knocking down the fences, cutting through the zip ties. Then they came in droves, as the dozens of university police officers in riot gear quickly retreated to an inner ring of fencing.

Seizing the opportunity, the masked protesters ran toward the student center and breached the inner ring, picking up pieces of fencing and hurling them into the building’s windows. Glass shattered, but no one went inside, where Yiannopoulos was waiting for the event to begin.

As some protesters yelled obscenities at police, others toppled a generator and light pole police had set up, spray-painting “Milo” with an X through it. Then they lit it on fire. From their backpacks, the protesters hurled dozens of fireworks.

One of the black-dressed anarchists said he had been hit by nonlethal ammunition.

“The cops shot me with pepper balls,” said the 26-year-old man, who called himself Zombie. “It hurt.”

Carrying a thick black shield and wearing a milk-soaked kerchief over his face to protect against potential tear gas, Zombie said, “We’re anarchists.” Fellow protesters unfurled a banner reading, “This is war.”

Police soon declared an unlawful assembly and ordered everyone to leave, but hundreds of protesters stayed, filling the entire upper and lower plaza. “Turn on the dance music,” one masked woman yelled.

UC Berkeley junior Fatima Ibrahim, 20, who clutched a “resist fear” sign with a red fist, said the timing of Yiannopoulos’ scheduled appearance stung.

“As a black Muslim woman, all three of those identities have been targeted throughout (Trump’s) campaign,” Ibrahim said. “To have someone like (Yiannopoulos) come into my campus and affirm those people’s beliefs, it’s very, very hurtful.”

Hours after the event was canceled, the College Republicans issued a statement declaring the Free Speech Movement dead. “It is tragic that the birthplace of the Free Speech Movement is also its final resting place,” the statement said.

San Francisco Chronicle staff writer Sarah Ravani contributed to this report.

Michael Bodley and Nanette Asimov are San Francisco Chronicle staff writers. Email: mbodley@sfchronicle.com and nasimov@sfchronicle.com