BENGHAZI - Militants claiming loyalty to Islamic State killed 40 people by blowing themselves up in cars laden with explosives in eastern Libya on Friday in an attack retaliating for Egyptian air strikes on Islamist targets.

Three car bombs exploded in Qubbah, a small town near the seat of the official government in what appeared to be another higher profile attack by the group after the storming of a Tripoli hotel and the killing of 21 captive Egyptian Copts.

On Monday, Egyptian air force jets bombed suspected Islamic State targets in Derna in far eastern Libya, a day after the ultra-radical group released a video showing the Egyptian Coptic Christian migrant workers being decapitated on a beach.

Four years after rebels overthrew Muammar Gaddafi, the oil-producing North African state is in chaos, with two governments and parliaments allied to armed factions fighting for control, while militant groups exploit a power vacuum.

“They killed and wounded tens in revenge for the bloodshed of Muslims in the city of Derna,” said a statement issued by the “Islamic State, Cyrenaica province”. It could not be verified by Reuters but this group has issued statements before.

Three bombs exploded shortly before Friday prayers at a petrol station, the local security headquarters and the town council in Qubbah, hometown of Parliamentary Speaker Aguila Saleh, security officials said. His house is close to the town council.

Around 40 people were killed, among them three Egyptians, and 70 wounded, security officials and medics said.

There have been suicide and car bomb attacks mainly in the east of Libya but the targets have tended to be police and army bases rather than civilians, with security officials blaming militant groups such as Ansar al-Sharia.

“We are announcing seven days of mourning for the victims of Qubbah,” Saleh told Al Arabiya television. “I think this operation was revenge for what happened in Derna,” he said without elaborating. He said he was outside Derna at the time of the attacks.

The internationally recognised prime minister, Abdullah al-Thinni, is based in Bayda, some 40 km (25 miles) from Qubbah. Saleh works out of Tobruk, another eastern town now home to the House of Representatives, the elected parliament.

The capital Tripoli on the Mediterranean coast in the far west is under the control of a rival government and parliament, set up after a faction called Libya Dawn seized the city in summer, forcing Thinni to flee to the east.

Neighbouring states like Egypt and Western powers are alarmed by a spread of militant in Libya.

Last month, militants claiming affiliation with Islamic State stormed the Corinthia luxury hotel in Tripoli, killing five foreigners and at least four Libyans. Supporters of the group, which has seized large areas of Iraq and Syria, have also taken over government and university buildings in Sirte, a central city and birthplace of Gaddafi, according to residents.