A lawmaker says suspected Islamic State militants attacked a small town in central Libya, killing at least three people, including the mayor.

Ismail al-Sharif said on Tuesday the attack happened overnight. He says the militants torched several houses in the town of al-Fuqaha, south of the coastal city of Sirte, a former IS bastion. IS had also attacked the town in October.

Resident Rabie al-Zidani says the mayor and two other security officials were beheaded in al-Fuqaha.

The attack comes as rival Libyan forces are fighting for control of the country's capital, Tripoli, where the death toll from days of fighting has risen to 51, including both combatants and civilians.

Libya plunged into chaos after the 2011 uprising and is governed by rival administrations, based in country's east and west.