So-called 'Islamic State' affiliates in Libya briefly took over the security headquarters in the western city of Sabratha, killing and beheading 12 security officers before being driven out, city officials said.
The incident early on Wednesday highlighted the enduring presence and unpredictable striking power of the local IS militants in the strategic city which serves as a hub for migrants heading to Europe.
Taher al-Gharabili, head of Sabratha Military Council, told the Associated Press that the gunmen "exploited a security vacuum" by deploying in the city centre as the military was occupied carrying out raids elsewhere.
A second security official said the militants used the headless bodies of the officers they killed to block the roads leading to the security headquarters - which they occupied for about three hours.
The official said the total number of officers killed in the occupation and ensuing clashes reached 19.
Sabratha has become the latest Libyan power centre for the local IS affiliate. Last week, US air strikes killed dozens of suspected militants in the city along with two Serbian hostages kidnapped last year.
Libya's chaos, five years after the uprising that led to the ousting and killing of longtime autocrat Muammar Gaddafi in 2011, has paved the way for the IS affiliate to take control of several cities.
The divided country is ruled by two parliaments: an internationally recognised body based in the eastern city of Tobruk and a rival government, backed by Islamist-allied militias, which controls the capital, Tripoli.
The United Nations brokered a deal last year to unite the country's various factions. A new unity government is awaiting endorsement by the eastern parliament.
The unity government could pave the way for an international military intervention against the Islamic State group.
The extremist group has previously taken over the city of Darna, before being driven out, and still controls the central city of Sirte, Gaddafi's home town.