TRIPOLI (Reuters) - At least four people were killed in a gun attack by suspected militants on a checkpoint east of the Libyan capital Tripoli on Thursday, a local official and a resident said.

The attack took place between the towns of Zliten and Khoms on the coastal road leading from Tripoli to the port city of Misrata, Zliten mayor Miftah Hamadi said.

Islamic State militants, who are 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 have benefited from the turmoil that followed a Nato-backed uprising in 2011.

Islamic State has 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, southeast of Misrata, in 2016, but Libyan and Western officials say militants have 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 based in Tripoli and the east of the country.