Witnesses said that when a young man briefly climbed onto the palace wall, that crowd chanted for him to get down, eager not to provoke a confrontation with the riot police.

But the peace did not last long after dark. A small group of protesters threw fire bombs over a palace gate, and launched fireworks toward buildings on the palace grounds. Officers inside fired a water cannon back to disperse demonstrators but also to douse small fires.

Within an hour, the fighting had intensified, with armored personnel carriers advancing and firing tear gas into the crowd, which was forced back several blocks from the palace. Security officers set fire to tents set up by protesters across the street from the palace and threw flags and banners on bonfires in the street.

The riot police officers, who report to the Interior Ministry, also captured and beat several protesters, witnesses said. In one of the beatings, which was captured on live television, officers could be seen dragging a naked middle-aged man, covered in soot, across the asphalt toward an armored personnel carrier. For many, the image served as a reminder that more than two years after Egypt’s uprising, the Interior Ministry remains one of the country’s many recalcitrant institutions, unreformed by Egypt’s new leaders and saddled with poorly trained officers who resort quickly to abuse. The Interior Ministry said it would investigate the beating.

In recent days, signs emerged that Egypt’s political elite, unnerved by the sudden erosion of the state’s authority, were working to settle some of their differences. Earlier this week, opposition parties reached across ideological lines for the first time, as a hard-line Islamist party joined with the National Salvation Front to put pressure on Mr. Morsi to form a new government.

Then on Thursday, a group of young revolutionaries managed to organize a meeting between opposition leaders and representatives of the Muslim Brotherhood. The meeting did not result in any breakthroughs, but the simple act of putting the antagonists in the same room was seen as a step forward.

Those efforts appeared to come undone on Friday.

The violent turn was met with anger by some anti-government activists. On Twitter, one activist, Tarek Shalaby, wrote: “I always support facing the regime’s thugs, but this time, a bunch of idiots started attacking the police behind the gates for no reason.”

Shady el-Ghazali-Harb, a young organizer who helped guide the revolt against Hosni Mubarak two years ago, was on the scene with a gas mask draped around his neck. “As long as the demands of the people are not met, people will stay in the street, and no one can control this violence,” he said, arguing that the underlying issue was the Constitution’s failure to address the revolution’s goals — bread, freedom and social justice, as the familiar chant goes.