Gunmen have stormed police headquarters in Libya's second city Benghazi before dawn sparking fighting in several districts that killed at least nine soldiers and police, medical and military sources said.

Special forces intervened to try to evict the gunmen triggering fighting elsewhere in the eastern city that also wounded 12 soldiers, the sources said.

An earlier toll said at least five soldiers were killed in the violence.

The gunmen were trying to seize a vehicle packed with weapons and ammunition that the police had taken from them, a security source said.

An army officer, who declined to be named, told AFP news agency that four of the soldiers killed died as they were heading back to their barracks after fighting had subsided.

Friday's violence comes just days after a car bomb targeted a special forces barracks in Benghazi, killing two soldiers and wounding three.

The government has been struggling to consolidate control in the country, which is effectively ruled by a patchwork of local militias and awash with heavy weapons looted from Muammar Gaddafi's arsenals. 

Source: AFP