CAIRO — Egypt’s bitter split over who should be ruling the country exploded into violent clashes in the streets of Cairo and elsewhere on Friday as masses of demonstrators celebrating the ouster of President Mohamed Morsi battled crowds of Islamists who wanted him reinstated.

Combatants used rocks, sticks, fireworks and Molotov cocktails in a battle lasting hours that raged near Tahrir Square and across a bridge spanning the Nile, part of the most widespread street violence in Egypt since the early days of the 2011 revolution.

The mayhem capped a day full of massive and defiant protests by Islamists demanding that Mr. Morsi be returned to power. At least four people were killed and many were wounded when security forces fired into a protest near the officers’ club of the powerful Republican Guard, where many believed Mr. Morsi was detained.

With clashes breaking out late into the night, it was impossible to estimate the full extent of casualties and damage. But early Saturday, security officials said at least 30 people had been killed nationwide and hundreds wounded, many of them in Cairo.