The natural human reaction to mass murders by ISIS or their purported sympathizers in Paris, Beirut, and San Bernardino is grief, anger, and a demand to redouble efforts to “degrade and destroy” the organization. People have had similar reactions after every terrorist attack, whether it was committed by the PLO or the IRA, whether it was in New York on 9/11 or London on 7/7. Once the red mist of rage has lifted, however, it’s important to think coolly and calmly about the long-term strategy for ending the horrific violence.

In doing so, Western governments need to learn from history. During the Irish War of Independence in 1919, British Prime Minister David Lloyd George said he would never talk to the “murder gang” that was the original Irish Republican Army, but would defeat it. Two years later he was engaged in negotiations with the group’s leader Michael Collins. More recently, Dick Cheney expressed the same idea more pithily: “We don’t negotiate with evil; we defeat it.” In reality, however, we nearly always end up talking to terrorist groups rather than defeating them militarily. Instead of continuing to suffer from collective amnesia and repeating the same pattern again and again, it would be better to look back at what has happened over the past century and imitate the steps that have led to the successful conclusion of other conflicts.

The causes of ISIS’s violence in the West can only be tackled at their root in Iraq and Syria. That requires a convincing military strategy both from the air and on the ground. I don’t know anyone who seriously believes ISIS will be defeated by bombing alone—an army can only be driven out, and kept out, of territory it controls through the use of ground forces. So far the United States and its allies haven't come up with a convincing answer to the question of who will provide the necessary “boots on the ground” to do this, although the United States has started sending special-operations forces to both countries.

Even if the United States and its allies were able to beat the group back into being a guerrilla force again, as the White House has rightly emphasized, “there is no military solution” to the ISIS problem. Past experience demonstrates the need for a political strategy, as well as a military one, to defeat the idea behind a terrorist movement. If an armed group enjoys significant political support—unlike the small 1970s-era groups like Germany’s Baader-Meinhof gang or America’s Symbionese Liberation Army—ending its violence has historically required addressing the grievances on which the group feeds and, in the end, negotiating with its leaders. In the words of Hugh Orde, the former police chief in Northern Ireland, there are almost no examples in the world of such a terrorist group being “policed out.”

If there is a political issue at the heart of a conflict, it needs a political answer. The violence of the Provisional IRA—the original Irish Republican Army’s successor, which engaged in a three-decade terrorist campaign to drive the British out of Northern Ireland—was constrained and undermined by security and intelligence work in the 1980s and 1990s. But the conflict was only finally ended by the decade-long negotiations that led to the Good Friday Agreement in 1998 and the Saint Andrews Agreement in 2006, for which I was the chief British government negotiator. After 30 years of fighting, the Free Aceh Movement’s guerrilla campaign in Indonesia only ended through the negotiations led by former Finnish President Martti Ahtisaari in 2005. The FMLN in El Salvador wasn’t defeated by more than a decade of American-backed military campaigns, but only ended after UN-brokered talks in 1992. A terrorist campaign by the Moro Islamic Liberation Front in Mindanao in the southern Philippines was only ended after negotiations with the government of President Benigno Aquino in 2014.

There are many more such examples, but almost no examples of a terrorist campaign with widespread political support being brought to an end by military means alone. Such negotiations do not always succeed the first time around. In Aceh, in Spain with ETA, and in Northern Ireland, eventual success was built on a series of failed negotiations. There is no such thing as an insoluble conflict with an armed group—just one that hasn’t been solved yet.

Of course people argue that ISIS is completely different from anything we have seen before. But people have said that about each new armed group since the rise of the IRA in 1919. It is true that ISIS is religiously inspired—in the words of a former Israeli cabinet minister, “God doesn’t compromise.” Governments have, however, made peace with Islamic guerrillas before, including the Free Aceh Movement and the Moro Islamic Liberation Front, so it is not impossible to do. Others suggest that ISIS fighters are nihilistic psychopaths and thus not capable of rational negotiations. On the contrary, ISIS’s sophisticated military and media strategies show that its leaders are unfortunately very shrewd, as well as very brutal. ISIS is indeed different from past groups, just as those groups were different from each other, but the question is whether that means the lessons of history no longer apply. I doubt it.

A political strategy to deal with ISIS is thus ultimately likely to mean negotiations with the core leadership, however much we despise the group’s methods. It may seem outlandish that a creed as absurd as ISIS’s should enjoy political support, but on the other hand, it is very hard to see how 2,000 fighters were able to take the Iraqi city of Mosul, population about 1.5 million, without it. And any political strategy will need to address the sources of this support—particularly Sunni alienation. In Iraq, a major cause of this was the corrupt and sectarian rule of Nouri al-Maliki’s Shiite-dominated government in Baghdad, which made even ISIS seem preferable among some Sunnis. It’s no coincidence that the self-styled Islamic State caliph Abu Bakr al-Baghdadi draws many of his deputies from among former officers in Saddam Hussein’s army and members of the Baath party. It is less likely that those individuals have suffered some sudden genuine conversion to an extreme sect of Islam than that they see an opportunity to fight the Shiite majority that has ruled the country since the fall of Saddam’s minority Sunni-dominated regime. In Syria the domination of the Assad family and their Alawite backers have had much the same effect on Sunnis there. There are, in other words, genuine grievances underlying ISIS’s resilience in Mesopotamia.

Who should be talking to ISIS? Like the Taliban in Afghanistan—who have been in on-again, off-again talks with the U.S. government for several yearsthey are likely to want to talk in the first instance to those who are fighting them, in other words the Americans and their allies, not least since they do not accept the legitimacy of governments in Baghdad and Damascus. Their immediate aim will be to reduce the military pressure they face. It should ultimately be legitimate governments in Iraq and Syria—which in the latter’s case will almost certainly require the removal of Bashar al-Assad—that work with Sunnis to determine their place in society, perhaps through the creation of autonomous Sunni regions comparable to the Kurdish Regional Government in Iraq. In the same way, the Afghan government will be the Taliban’s interlocutor if and when peace talks finally take off in Afghanistan.

What is there to talk about with such a horrific and fascistic group? For one thing, it is important to understand that talking with terrorists is not the same as agreeing with them. In the 1990s, the British government would never have been prepared to talk to the IRA about a united Ireland at the barrel of a gun and against the wishes of the majority of the people living there. When we sat down with the Republicans, however, we found that there were a series of legitimate subjects they wanted to discuss—from power-sharing between Catholics and Protestants to the protection of human rights. It is not impossible that the same pattern could be repeated with ISIS. No one is going to be interested in discussing a universal caliphate, but there are issues that can legitimately be discussed, starting with the oppression of Sunnis and future efforts to forge for them a comfortable place in both Iraq and Syria.

Moreover, such negotiations are dynamic, not static. Positions change as part of a process. Even if some of the hardline leaders of ISIS, particularly the foreign fighters, want nothing less than their full demands (including ushering in the apocalypse), other more moderate leaders will, under military pressure, be prepared to settle for more modest gains. The aim should be to strengthen those moderates’ positions in ISIS’s internal discussions. Such a negotiation would not be easy, but it is possible to imagine a solution that includes autonomy for Sunni communities in both Iraq and Syria, respect for their rights, and oil-revenue sharing that allows a viable system of government.

Of course some will insist that Sunni grievances in Iraq should be discussed only with Haider al-Abadi’s government in Baghdad, and not with ISIS. Certainly replacing Maliki with Abadi was an improvement from the point of view of Sunnis, but it is equally clear that many Sunnis, and not just ISIS supporters, remain alienated from Baghdad. One of the many mistakes the U.S., U.K., and their allies made in Iraq was to pull out in 2011 without ensuring power-sharing or at least an effective dialogue between Sunnis and Shia there. A major external effort will now be required to create such a dialogue.

In Syria there is no legitimate government for the Sunni opposition to talk to, and the principal efforts of the non-ISIS opposition will continue to be focused on removing Assad rather than fighting the group. The first objective of negotiations should be inter-sectarian dialogue with more moderate opposition groups to try to split off Sunni support from ISIS. But in Northern Ireland, while we started trying to make peace between the more moderate Ulster Unionist Party and Catholic SDLP, we ended having to conclude the agreement between the more hardline Democratic Unionist Party and Sinn Fein, and I suspect something similar will be true in Iraq and Syria. We will again have to speak to the extremes if we want to silence the guns for good.

I am not arguing that those of us in the anti-ISIS coalition should try to sit down with Mr. al-Baghdadi now, even if he wanted to do so. Past experience tells us, however, that it would be sensible to open a secret channel now so we can communicate with ISIS and put ourselves in a position to negotiate once we have arrived at a “mutually hurting stalemate” in which both sides realize they cannot win militarily. That is what has happened in previous cases. The British government, for example, opened a secret channel to the IRA in 1972, even though the real negotiations didn’t start until 1992.

I am also not for one moment suggesting that talking is an alternative to fighting ISIS. We need to do both. If real military pressure—on the ground as well as from the air—is combined with attempts to address the Sunni grievances that fuel the conflict, and to offer ISIS’s supporters a political way out, then maybe the world will eradicate the problem of ISIS, just as we have eradicated the threat posed by previous armed groups. If we learn the lessons of the past quickly, rather than waiting for years and trying everything else, many fewer people may die in the Middle East and in the West.