The collapse of the Islamic State's self-proclaimed caliphate has benefited Iraq and Syria, the two countries where the extremist group once maintained its sanctuary, but it is also a threat to the nations where fleeing fighters might go next.

At the top of this list is Turkey, a logical landing spot for many fleeing Islamic State militants since it is next door to both Iraq and Syria.

In early February, the New York Times reported that “thousands” of Islamic State fighters have fled Iraq and Syria while a substantial number “have gone into hiding in countries like Turkey.” These revelations are nothing new. A 2016 interview by the Times correspondent Rukmini Callimachi with a former fighter from Germany revealed that the Islamic State deliberately dispatched hundreds of its fighters to Turkey. Smugglers on both sides of the border continue to move people, including Islamic State fighters, back and forth from Syria to Turkey, in some cases bribing Kurdish fighters so they can pass through territory controlled by the Syrian Democratic Forces.

In the aftermath of the Islamic State's deadly assault on Istanbul's Reina nightclub in the early hours of Jan. 1, 2017—an attack that killed 39 and wounded 71—it was revealed that the group had established robust terrorist cells in Turkey. There are two types of cell structures in Turkey: those composed of Turks and those manned by foreign fighters. The foreign fighter cells primarily consist of militants from the Caucasus, Uighur Turks from China, and Central Asians from the former Soviet Union, as well as fleeing Arab and European Islamic State fighters.

Istanbul has historical resonance to many Muslims as the previous seat of a Sunni caliphate. The fact that the Islamic State could not realistically hope to re-establish its caliphate on Turkish territory doesn't mean its fighters won't bring instability to Turkey; their mere presence will destabilize the country.

The growing number of Islamic State fighters will likely precipitate clashes with Turkish police and soldiers attempting to root them out.

In the past year, the Islamic State has been far more cautious in launching attacks on Turkish soil, perhaps to avoid scrutiny from the security forces. But the growing number of Islamic State fighters, which is estimated to be in the hundreds, will likely precipitate future clashes with Turkish police and soldiers attempting to root them out. There is also the possibility that a spectacular attack could be engineered from Turkish soil, as one nearly was when the components for an improvised explosive device were airmailed from Turkey to Australia last August.

Turkey could serve as a logistics hub to plot future attacks. Unlike many other terrorist sanctuaries, such as Afghanistan, Libya, and Somalia, Turkey is not a failed state. This is important because militants have easier and more reliable access to communications, transportation, and financial networks due to relaxed Turkish visa procedures, extensive airline connections, and shortcomings in financial tracking systems. Corruption and complicity among Turkey's security forces, including members of the armed forces and police, facilitate further access through a mixture of bribery and coercion.

The willingness of some Turkish politicians and high-ranking members of the security forces to counter the Islamic State is also in doubt. In early February, more than 10 high-profile Islamic State members—including the “emir” of Diyarbakir and militants who had been involved in bombing attacks in Istanbul, Ankara, and Gaziantep—were abruptly released by judges. In many cases, Turkish intelligence officials who did not see the group as the primary threat pressured the judiciary to let dangerous suspects go despite the fact that prosecutors had sought extremely long prison sentences for them. Since Turkey has been accused of recruiting thousands of former Islamic State fighters to attack Kurds in Syria, some speculate that the release of Islamic State members without explanation could be the result of a backdoor deal with the Turkish intelligence service. (One of us left the Turkish police force out of a refusal to work with President Recep Tayyip Erdogan's government and allow foreign fighters to pass through the southern Turkish city of Sanliurfa.)

Turkey has been accused of recruiting thousands of former Islamic State fighters to attack Kurds in Syria.

Over the past decade, Turkey has slowly developed into a country with dense pockets of support for Salafi jihadi groups, including the Islamic State and al Qaeda, in major cities, towns, and villages along the Turkish border with Iraq and Syria. Domestic stability in Turkey will hinge on radicalization trends, how varying degrees of support for jihad among the Turkish population (and growing refugee population) manifest themselves in the future, and on the intensity of the transnational Kurdish insurgency.

The threat posed by the Islamic State has been compounded by Erdogan's purges after the failed July 2016 coup that replaced the counterterrorism and intelligence forces, including the police, gendarmes, and portions of the military. As a result, relatively inexperienced and untrained recruits have been tasked with managing counterterrorism operations against a sophisticated adversary.

Another issue is Erdogan's priorities, which primarily revolve around consolidating power and continuing to purge any suspected collaborators in the 2016 coup attempt, as well as battling Kurdish militants, including the Kurdistan Workers' Party (PKK) and its allies in Syria, the People's Protection Units (YPG). The Turkish military's recent incursion into Afrin in northern Syria is a prime example of this.

Despite the fact that the Islamic State has slowly built up its presence in Turkey over the past several years, countering the threat from Islamic State-linked terrorists appears to be low on Erdogan's agenda. This is especially true when the Islamic State is helping Turkey by fighting against Kurdish groups in Syria, Turkey's perceived primary enemy, as it has in northern Syria and western Iraq at various points throughout the conflict.

Erdogan's continuing tolerance of Islamic State fighters on Turkish soil amounts to passive support and tacit approval. The danger posed by these fighters using Turkey as a staging ground could develop into a far more formidable threat than that currently posed by Kurdish terrorism. Tolerating the Islamic State in order to fight the Kurds is therefore a dangerous and myopic policy. It will further strain relations with the European Union and the United States on counterterrorism, cooperation, and visa-free travel. And when the Islamic State reaches a critical mass, it is likely to turn against its host, just as various militants once supported by Pakistan eventually turned their fury against the Pakistani state and its security forces.

When that day comes, harboring extremists will no longer remain viable for Erdogan and his supporters. But at that point it will be too late. Erdogan's willingness to ignore the threat from the Islamic State may be what ultimately leads to his political demise.

Colin P. Clarke is a political scientist at the nonprofit, nonpartisan RAND Corporation and an associate fellow at the International Centre for Counter-Terrorism in The Hague.

Ahmet S. Yayla is an adjunct associate professor at Georgetown University and a former counterterrorism police chief in Turkey.

This commentary originally appeared on Foreign Policy on February 15, 2018. Commentary gives RAND researchers a platform to convey insights based on their professional expertise and often on their peer-reviewed research and analysis.