IS has taken advantage of growing chaos to expand its foothold in the North African country, which has rival governments vying for power.
The jihadists' overnight seizure of the security headquarters and other buildings in Sabratha came days after a US air strike hit an IS training camp near the western city, killing dozens, probably including a senior IS operative.
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.
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.
The group has since attacked key coastal oil facilities and staged a string of suicide bombings.
