CAIRO — Militants pledging allegiance to the Islamic State claimed responsibility for three car bombs that killed at least 38 people in a town in eastern Libya on Friday in the latest escalation in a surge of violence linked to the group.

The attacks, in the town of Qubbah, appeared to be one more turn in a cycle of retaliation that began when the Islamic State, also known as ISIS or ISIL, released a video last week showing its fighters in western Libya beheading more than a dozen kidnapped Egyptian Christians. The government of Egypt responded with airstrikes on the city of Derna, a hub of Islamist militancy in eastern Libya where another group of fighters has pledged loyalty to the Islamic State.

On Friday, the Islamic State branch in Derna claimed responsibility for the latest bombings “in revenge for the bloodshed of Muslims” in the city, according to a Twitter message linked to the group and reported by Reuters. Other Twitter messages from the group claimed to identify two of its “martyrs” who died in the bombings.

Eight of those killed in Qubbah were Egyptians who had come to Libya for work, according to Mohamed Tumi, a Libyan government spokesman in Bayda. Officials initially said that at least 42 people had been killed, but later amended that number to 38. News reports said that three or four Egyptians had been killed. More than 40 others were injured.