Five people were killed and up to 15 wounded when suspected Islamist militants tried to storm Libyan government security headquarters in Benghazi on Friday, army officials said, setting off a firefight that lasted more than an hour.
The dead were soldiers and police officers, army officials said. Huge explosions could be heard during the fighting in the early morning.
Libya's central government is struggling to control armed groups, militias and brigades of former rebels who helped oust longtime leader Muammar Gaddafi in 2011 and now refuse to disarm.
Special forces have often clashed with Islamist militants in Benghazi, Libya's second-largest city that dominates the volatile eastern region, including from Ansar al-Sharia, listed as a terrorist organisation by Washington.
Armed men also attacked the apartment of Benghazi's security chief Colonel Ramadan al-Wahishi. He was not hurt, a security official said.
Special forces later secured the security headquarters, near the city center, with armed trucks and artillery cannons.
Car bombings and assassinations of soldiers and police officers have become common in Benghazi, where a suicide bomber detonated an explosives-packed minibus outside a special forces camp on Tuesday, killing two people and wounding two.
Most countries have closed their consulates in the city and some foreign airlines have stopped flying there since the U.S. ambassador and three other Americans were killed in an Islamist militant attack in September 2012.
In December, a suicide bomber killed 13 outside an army camp on the outskirts of Benghazi, in the first suicide attack since the 2011 NATO-backed civil war that toppled Gaddafi.
Western diplomats worry the violence will spill over to the capital Tripoli where the security situation has also worsened. Kidnappings of foreign diplomats have been on the rise as well as nightly shootouts near the airport road.
Western and Arab allies are training Libya's fledgling armed forces but the military is still no match for the heavily armed former rebels and militias who often use the threat of force to make demands on the state.