People hold up pictures of the 21 Egyptian Coptic Christians beheaded in Libya, as they gather in a gesture of solidarity in front of the Egyptian embassy in Amman February 17, 2015. The sign reads, "Daesh is terrorist, and so are those who support them". (Muhammad Hamed/Reuters)

THE HORRIFIC murder of as many as 21 Egyptian Christians by Libyan militants claiming allegiance to the Islamic State has underlined the need for international intervention in that North African country. But Egypt’s response to the atrocity — unilateral air attacks on what it said were Islamic State targets — offers an excellent example of what not to do.

Three and a half years after NATO countries abandoned Libya following the overthrow of dictator Moammar Gaddafi, the country is divided between two governments, parliaments and armies, with rival foreign sponsors. In the east, based in Tobruk, is a Western-endorsed secular government; in the west, controlling Tripoli, is a rival alliance of Islamists and regional forces, including minority Berbers. In the spaces between them flourish extremists.

The response of the United States and European Union to this mess has been to back the efforts of a United Nations mediator to broker a peace between the dueling factions and create a unity government. It’s a policy that doesn’t directly address the extremist threat, and mediator Bernardino León hasn’t made much progress, in part because his Western support is almost entirely rhetorical.

However, Egypt’s military-backed ruler, Abdel Fatah al-Sissi, has a far worse idea: He would like U.N. permission for a military intervention in Libya that would benefit the faction he supports, the secular regime in Tobruk. A former Libyan army general who leads forces there, Khalifa Haftar, has been backed by Egypt and the United Arab Emirates, who hope he will vanquish Libya’s branch of the Muslim Brotherhood and rule as a Sissi-like strongman.

Egypt’s unilateral airstrikes Monday were directed at Islamic State camps in Derna, even though the militants who murdered the Egyptian Christians were in another town, Sirte. But that’s not the only conflation in Cairo’s campaign. Just as he makes no distinction between terrorists operating in the Sinai Peninsula and the democratically elected Muslim Brotherhood politicians he deposed in a 2013 military coup, Mr. Sissi does not acknowledge a difference between the Islamic State militants and the Libya Dawn faction in Tripoli.

The last thing the United Nations or Western governments should do is pick sides in Libya’s civil war, or in the larger confrontation in the Sunni Muslim world between reactionary governments such as Egypt’s and Saudi Arabia’s and those that sympathize with Islamists, such as the governments of Turkey and Qatar. While terrorists must be fought everywhere, attempts to destroy Islamist political movements in countries such as Egypt and Libya are counterproductive and futile.

Libya needs concerted pressure to be brought on both sides to create a regime that can restore order, with help from an international force if needed. To gain leverage over the factions, Western nations should enforce an arms embargo; they could also hold Libyan oil revenues in escrow and freeze the government’s foreign assets pending a deal. At the same time, they should let Mr. Sissi and other Arab partisans know that their interventions are more likely to help than hurt the Islamic State.