Clashes between armed residents and members of a militant Islamic group in Libya's eastern city of Benghazi killed five people and wounded nearly 40 early on Monday, officials said.

The fighting started before dawn between armed citizens and members of the officially dissolved militant Ansar al-Shariah group, and later prompted the army's special forces to step in to quell the violence, said security officials. They spoke on condition of anonymity in line with regulations.

Sounds of explosions and gunfire echoed across much of the city, but mainly in the Raas Obeida district and surrounding areas. Clouds of black smoke hung over Benghazi as ambulances rushed the wounded to hospital.

The city's al-Jalaa hospital received the bodies of four soldiers and one civilian, according to the hospital spokeswoman, Fadya al-Barghathi.

Classes were suspended at the city's schools and local university, and most Benghazi residents stayed home because of the fighting. Mohammed Abu Sneina of Benghazi's local council warned that harsh measures would be taken against anyone who disturbs peace and security.

Libya has been roiled by unrest since the ouster in 2011 of longtime dictator Muammar Qaddafi. Armed groups that fought Qaddafi's army in 2011 have turned themselves into militias that exploited the weakness of the weak central government in Tripoli and now control the streets and operate independently of the police and the military.

Earlier this month, at least 40 people were killed when residents of the capital, Tripoli, took to the streets to protest the presence of militias in the city. The uprising forced several militias to leave the city and head back to their hometowns.

The frustrations over the militias felt by many Libyans encouraged the government to start a major push to gain full control the vast, oil-rich North African nation.