By 2013, many of those militias had split into two camps in a broad civil conflict. On one side, some Islamist and other local militias were aligned behind a faction based in Misurata with its own provisional government in Tripoli, the capital. Other forces opposed to the Islamists lined up with an anti-Islamist military leader, Gen. Khalifa Hiftir, who presented himself as a national savior. Most of the elected Parliament and, thus, the internationally recognized government moved to the eastern towns of Tobruk and Bayda under his protection.

With each side focused on battling the other, militants pledging allegiance to the Islamic State took full control of Surt, a coastal city, established a base at Derna, and became a third force in the bloody conflict. The Islamic State fighters feuded with other Islamists, carried out mass beheadings of Christian migrants, and threatened attacks across the Mediterranean as well. But no Libyan government or faction has yet focused its full capabilities on eradicating the group.

In Derna, the backlash against the Islamic State began after the group’s fighters killed a revered leader of a powerful local Islamist militia, the Martyrs of Abu Salim Brigade. In Surt, the rebellion appears to have been set off by the group’s killing of a popular preacher. Yet one of the largest tribes in the area, the Ferghani, is said to have led the fighting against the Islamic State there.

Reports emerging from Surt say the militants have tried to break the uprising with artillery fire, summary executions and by hanging dead bodies from lampposts.

“The sons of Surt are being dangled from light poles and from the city’s bridges for no reason other than they refused to pledge allegiance to that group,” Mohamed Hadya al-Ferghani, a member of the tribe, said this week in an interview with a Libyan satellite network. “The knife was put on the neck of a whole tribe that refused to pledge allegiance to that group, and it is the beginning of the knife of the Islamic State being up against the neck of the world as well.”

Mr. Dayri, the foreign minister, accused the Islamic State militants of beheading at least 12 people last Friday, exhuming and incinerating the body of an imam, and publicly crucifying three other preachers. Because of the Islamic State’s dominance over the city, none of the reports could be confirmed independently.

In response to Mr. Dayri, the Arab League said in a statement on Tuesday that it would “ask member countries to help support Libya in its war against terrorism” and “help it with all means necessary to maintain security.”