Jihadist group Ansar al-Sharia on Monday attacked Libyan special forces in the eastern city of Benghazi, the army said, sparking an all-out battle in which at least five soldiers died.
It was the first such confrontation between the army and Libya's top jihadist group.
"A violent clash has been taking place for several hours between our forces and an Ansar al-Sharia cell," Colonel Milud al-Zwei, spokesperson for Libya's special forces, said.
Medics at the city's al-Jala hospital, said five soldiers were killed and 23 people wounded, including 10 civilians.
The number of casualties on the jihadists' side was not immediately known as they were being treated in a clinic run by Ansar al-Islam.
According to Zwei, the fighting broke out after a special forces patrol near the group's headquarters came under attack.
"The army retaliated, sparking clashes with all types of weapons," he said.
Explosions and gunfire
The spokesperson said fighting between the two sides spread to other districts of Benghazi, especially near a charity clinic run by Ansar al-Sharia in the Selmani area.
Explosions and gunfire could be heard in several districts, an Agence France-Presse journalist said.
Witnesses said gunmen had set up checkpoints on roads leading into Benghazi to prevent reinforcements reaching the Islamists.
Ansar al-Sharia emerged after the 2011 fall of Moamer Kadhafi's regime, with its military wing composed of former rebel fighters.
Blamed for the murders of judges and security personnel in Benghazi, it is also suspected of responsibility for a September 2012 attack in which the US ambassador and three other Americans were killed.
It denies any involvement.
Integrate former rebel fighters
Ansar al-Sharia, which demands implementation of sharia Islamic laws as the sole source of legislation, controls areas of Benghazi as well as Syrte and Derna, also in eastern Libya.
Libyan and foreign analysts say Islamist groups are held responsible for much of the violence in eastern Libya but that the government has been loathe to take on the heavily-armed groups for fear of reprisal.
Ansar al-Sharia itself has said it does not recognise state institutions or its security forces, even as the government struggles to integrate former rebel fighters into a regular army and police force.
The bloodshed in Benghazi comes as the authorities have been taking steps to evacuate militias from Tripoli, on the back of popular discontent in the capital against armed groups.
On November 15, 46 people were killed and more than 500 wounded in clashes in Tripoli after militiamen opened fire on peaceful demonstrators calling for them to leave the city.
In similar protests, Benghazi residents had in September 2012 managed to dislodge Ansar al-Sharia from their headquarters, only for the jihadists to return a few weeks later. – AFP