An attack on a checkpoint between the Libyan capital and the town of Zliten killed four soldiers of the UN-backed unity government on Thursday, the town's mayor said.
"The attack was carried out with grenades and light weapons at 7:45 AM (0545 GMT). Four people were killed and five wounded," Mayor Moftah Ahmadi told AFP.
Zliten lies 170 kilometers east of the capital in an area of western Libya under the control of the beleaguered Tripoli-based government.
The mayor said the attackers hit a checkpoint manned by special forces from the interior ministry, on the main highway along the Mediterranean coast.
"According to preliminary reports, there were three attackers and one of them was killed in the exchange of fire with the forces manning the checkpoint," Ahmadi said.
Zliten security chief Mohammed Abu Hajar told Libya's Al-Nabaa television that the attack was the work of the Daesh group, although there was no immediate claim of responsibility from the militants.
Daesh took advantage of the anarchy that reigned in Libya after the NATO-backed overthrow and killing of longtime dictator Muammar Gaddafi in 2011 to establish footholds in several parts of the country.
In June 2015, they seized control of Gaddafi's hometown of Sirte, only ceding it in December of the following year in the face of an offensive by the Tripoli-based government's forces and allied militias.
The militants have continued the fight from rural areas of western Libya, including around Zliten, and in April the Tripoli-based Government of National Accord (GNA) launched a campaign to flush them out.
The GNA has struggled to assert its authority outside western Libya since its formation in 2015.
The east, including the second city Benghazi, is largely in the hands of the self-styled Libyan National Army of Field Marshal Khalifa Haftar.