CAIRO — Dozens of people were killed in the Libyan capital, Tripoli, on Friday after militiamen opened fire on unarmed protesters, setting off some of the worst violence in the capital since the revolt against Col. Muammar el-Qaddafi almost three years ago.

The bloodshed at the protest on Friday afternoon quickly devolved into clashes involving armed citizens and rival militias, witnesses said. At hospitals, bodies arrived mangled by heavy-weapons fire. Air force jets flew sorties over the city, as pickup trucks carrying reinforcements of fighters raced to the clashes.

The protest that led to the violence was part of a rising tide of citizen anger against Libya’s multitude of militias, made up of thousands of men who fought Colonel Qaddafi’s forces and never laid down their arms. The militias have fed Libya’s chronic insecurity, fighting among themselves while exerting control over vital installations and even resources like oil. Fighters pledge loyalty to their commanders, tribes or towns, rather than the weak central government.

Yet the nature of the violence on Friday seemed to represent an especially ominous turn for the country, dragging it back to the winter three years ago when Colonel Qaddafi’s soldiers, roaming the capital in jeeps, gunned down protesters in the streets.