IS has taken advantage of growing chaos to expand its foothold in the North African country, which has rival governments vying for power.
IS fighters exploited the "security vacuum" in the city centre as security forces loyal to authorities in militia-held Tripoli conducted raids looking for IS operatives in the suburbs, Sabratha's municipal council said in a statement.
Up to 200 IS fighters from "sleeper cells" seized the chance at around midnight Tuesday to take control of the security headquarters and other buildings, Taher al-Gharabli, the head of the city's military council, told television.
Ten members of the security forces were killed when IS attacked the security base, while six others died in clashes before and afterwards, military council spokesman Adel Benwir said. Security forces have since regained "complete control," Benwir said.
"Some IS fighters are south of the city," he added, without giving a number. Libya has had rival administrations since mid-2014 when the internationally recognised government fled Tripoli after the Fajr Libya militia alliance overran the capital and set up its own parliament.
Last June, IS seized the coastal city of Sirte, east of Tripoli, raising fears that it is establishing a new stronghold on Europe's doorstep. The group has since attacked key coastal oil facilities and staged a string of suicide bombings.