At least four people were killed in a gun attack by suspected militants on a checkpoint east of Tripoli, a local official and a resident said.
The attack took place between Zliten and Khoms on the coastal road from Tripoli to Misrata, Zliten mayor Miftah Hamadi said.
Islamic State militants, active in the area, were thought to be behind the attack, he added. Security personnel at the checkpoint were among the dead, a local resident said.
Libya has seen occasional attacks by Islamist militants who benefited from the turmoil following a Nato-backed uprising in 2011.
Islamic State said it was behind a deadly attack by gunmen on the offices of the electoral commission in Tripoli in May and an attack on a court complex in Misrata last year.
Local forces drove the militant group from its former stronghold in Sirte in 2016, but Libyan and Western officials say militants sought to regroup through mobile desert units and sleeper cells in northern towns.
The United Nations is leading efforts to prepare for national elections in Libya, which it hopes will reunify rival factions in Tripoli and the east of the country.