At least four soldiers and one civilian have been killed after special forces clashed with armed fighters in the eastern port city of Benghazi, the army has reported.
The interim leader of Libya's army warned of a "bloodbath" as the unrest in the city flared up again, a week after clashes there killed more than 30 people.
Shortly before dawn, heavy gunfire and explosions could be heard near the headquarters of the special forces, not far from the city centre.
The Facebook page of the special forces said its members were exchanging light arms and rocket fire with an "outlaw" group and reported that two of its fighters had been wounded.
A little later it posted photos of three of its members and announced that they had been shot dead as they "were defending the legitimacy of the state with courage and honour".
The clashes came just hours after dozens of protesters forced a brigade of former rebel fighters from their base in Benghazi on Friday evening.
The demonstrators had burned two vehicles belonging to the First Infantry Brigade, before moving on the barracks, said a Libyan army officer.
The brigade was forced to abandon its headquarters as the protesters took it over.
A witness on site said the demonstrators, some of whom were armed, had fired in the air and launched a rocket-propelled grenade at an external wall of the barracks, though nobody was hurt.
The brigade was set up by former rebel fighters who helped overthrow the former leader Muammar Gaddafi in 2011. It says it takes its orders from the defence ministry.
Following that first attack, Salem al-Konidi, the interim head of the army, said on the Al-Aseema television channel late on Friday: "If the special forces are attacked, there will be a bloodbath ... There could be a catastrophe in Benghazi."
Konidi is the interim replacement for General Yusef al-Mangoush, who resigned last Sunday, a day after fighting in Benghazi killed 31 people and left dozens more wounded.
Mangoush had come under mounting criticism for having failed to form a national army in the face of resistance from militias unwilling to surrender their independence.