BERKELEY, Calif. — A speech by the divisive right-wing writer Milo Yiannopoulos at the University of California, Berkeley, was canceled on Wednesday night after demonstrators set fires and threw objects at buildings to protest his appearance.

The university announced the cancellation on Twitter around 6 p.m. local time, about an hour after a section of the campus erupted in protest.

All buildings on campus were locked down for several hours, and the university police said on Twitter that students should leave the area because of the “violent demonstration.” The lockdown was lifted around 10:55 p.m. local time.