ISTANBUL — The northwestern corner of Syria is home to a dizzying spectrum of anti-Assad forces. Weapons — and fighters — have amassed in the area in large part thanks to Turkey’s “open door” policy, which makes the passage relatively painless. When Turkey’s ethnic brethren, the Turkmen, recently became the targets of Russian air strikes — prompting, perhaps, Turkey’s decision to shoot down a Russian fighter jet on November 24 — the incident brought Turkey’s murky relationship with a tangled web of jihadist groups to the fore.

Ankara’s ties with the extremists are anything but straightforward. What’s clear is that Turkey has taken clear sides in the civil war in Syria, took a laissez-faire approach to the frontier with Syria and more recently felt the terrorist blowback from Syria.

Turkey differs with its allies on which opposition forces to support in Syria, a thorny issue further complicated by the emergence of ISIL. Apart from ISIL, jihadist groups in Syria include al-Nusra Front (al-Qaeda’s Syrian branch), Ahrar al-Sham, and various more loosely formed militias from the Caucasus and elsewhere.

Former U.S. ambassador to Turkey Francis Ricciardone rebuked the Turks, saying “we will not work with them, and we’d rather you not work with them, and we think they need to be blocked from transiting your borders.”

Vice President Joe Biden took a similar position, criticizing “the Turks, the Saudis, the Emiratis” for supporting “anyone who would fight against Assad,” a category which came to include al-Nusra and other extremists. Despite these statements, radicals in Syria have regularly received military supplies from Saudi Arabia and Qatar via Turkey, with the full knowledge of the CIA.

Turkey is at odds with three of ISIL’s rivals, namely the Kurds, Shiite Arabs and the Assad regime. Since the beginning of the Arab Spring in 2011, Ankara has done everything in its power to topple Assad. The Kurdish Democratic Union Party (PYD) — which has fought ISIL over cities like Kobane and Haseke for months — is the Syrian branch of the Kurdistan Workers' Party (PKK), against which Turkey has waged its own 30-year war. Ankara is not happy to see a Shiite government in power in Baghdad either, and has misgivings about Iran’s growing influence in southern Iraq.

Turkey and ISIL now share regional enemies.

* * *

ISIL’s rise goes hand in hand with the failure of the Turkish project to create a “Muslim Brotherhood belt” stretching from Tunisia to Syria under Ankara’s leadership. Gulf countries like Saudi Arabia and the UAE consider democratically elected Islamists threats to their monarchies, and have opposed Muslim Brotherhood parties in the region since 2013, much to Turkey’s chagrin.

In Egypt, Saudi Arabia openly supported the coup against Mohamed Morsi, partly out of a wish to counteract the influence of the Muslim Brotherhood-affiliated Sahwa al-Islamiyya (Islamic Awakening), which also has a presence in Saudi Arabia.

While the Muslim Brotherhood was an important part of the opposition to Assad in 2011, the ensuing civil war soon brought radical Salafist groups to the forefront. Across the Middle East, Brotherhood-affiliated parties that four years ago seemed poised to become counterparts to the AKP are now on the ropes. They have given way to radical Salafist groups — influenced by the Saudi-bred ideology of Wahhabism — that amass power undemocratically, through violence.

In the competition for prestige between the Sunni-majority nations of the Middle East, Turkey has lost ground to Saudi Arabia and its Wahhabi ideology — the most radical proponent of this ideology being ISIL itself.

Ankara has adapted its rhetoric to this changing landscape. Though Turkey calls ISIL a terrorist organization, it never misses a chance to point to the fact that the plight of Iraqi and Syrian Sunnis contributes to its presence in the region. Sunnis oppressed by the Shiite government in Baghdad and by the Assad regime in Damascus, so the argument goes, come to see ISIL as their only hope for salvation.

In August 2014, Turkish Prime Minister Ahmet Davutoğlu said ISIL came to power as the result of Sunnis’ “discontent, anger, marginalization, and humiliation,” and that “if Iraq’s Sunni Arabs had not been excluded from the [electoral] process, there would not now be such pent-up anger in provinces of the Sunni heartland like Mosul and Anbar.”

Notably, just two months before Davutoğlu made his remarks, ISIL captured Mosul and took 49 diplomats from the Turkish consulate, which Ankara had persistently refused to evacuate, as hostages. When ISIL released them three months later, rumors that Turkey had freed a number of ISIL militants in exchange ran wild.

Turkish President Recep Tayyip Erdoğan did not confirm or deny the claims, and merely stated, “Even if such an exchange took place, as president I regard these 49 citizens of mine as irreplaceable.”

* * *

The most outspoken critic of Turkey’s ISIL policy is Russian President Vladimir Putin who, as soon as the Russian jet went down November 24, remarked, “The loss we have suffered today is a stab in the back delivered by terrorists’ accomplices.” He also hinted that ISIL had been selling its smuggled petrol in Turkey.

While Putin accused Turkey of allowing ISIL to smuggle oil across its border, the U.S. Treasury Department said that the Assad regime — which is supported by Russia — has been buying oil from ISIL, and imposed sanctions on the Syrian, Cypriot, and Russian businessmen allegedly at the center of the oil trade between Damascus and the Islamic State.

ISIL is selling a great deal of oil to the Assad regime, some is coming across the border into Turkey — Adam Szubin

Recently U.S. Treasury Department official Adam Szubin said "ISIL is selling a great deal of oil to the Assad regime," but also added "some is coming across the border into Turkey."

It has long been claimed that ISIL has taken advantage of Iraq and Syria’s porous borders, as well as the black market economy created by the ongoing conflicts there, to sell its oil in Turkey and other neighboring countries.

In a 2014 speech, the American Secretary of State John Kerry called out Turkey, along with Lebanon, as the main destination for ISIL’s black-market petrol. Similarly, an OECD report titled “Financing of the Terrorist Organization Islamic State in Iraq and the Levant” states: “Following capture of oil fields by ISIL by summer 2014, the seizures of smuggled oil increased sharply, reaching 20 million liters at the seven Turkish provinces bordering Iraq and Syria.”

The Turkish press has also made many allegations concerning human trafficking and smuggling along Turkey’s border with ISIL. According to their reports, the criminal activity takes place with the tacit consent of local security forces, who are bribed to look the other way.

* * *

Sympathy for ISIL militants among Turkish Islamists is another cause for concern. Official figures put the number of ISIL militants of Turkish origin at approximately 1,300. The New York Times described how ISIL had set up a recruitment center in the Ankara slum of Hacıbayram, where considerable numbers of local people have already joined the organization.

In July, pro-ISIL groups gathered in Istanbul to celebrate the end of Ramadan, without any intervention from the police. ISIL fighters wounded in battle are said to have received treatment in Turkish hospitals — to which Turkey’s Minister of Health responded, “Our duty is to treat patients, not interrogate them. We have no way of knowing if a wounded person belongs to ISIL.”

Things took a serious turn for the worse in June, when ISIL began using Turkish citizens to carry out suicide bombings on Turkish soil. When two ISIL suicide bombers struck Ankara in October, they killed 102 people in the deadliest terror attack in Turkish history. The bombings occurred just a few kilometers from the Turkish Parliament, the prime minister's office, the office of the Turkish armed forces’ chief of staff, and the country’s National Intelligence Organization — a clear sign of ISIL’s potential to inflict harm at the very core of the country.

It is probably no coincidence that ISIL’s chief targets in its most recent attacks in Turkey have been Kurdish and leftist, secular groups. Over the past 13 years, Turkish society has witnessed rising polarization between secularists and Islamists, and — more recently — between Turks and Kurds as well. Thus ISIL’s attacks seem calculated to increase pressure on the country’s main social and ethnic fault lines.

Though ISIL was the sole party responsible for the attacks, the Turkish government has bizarrely insisted on describing it as part of a so-called “terrorism cocktail” which includes the PKK/PYD and other leftist groups. Not surprisingly, Turkish society has failed to unite in the aftermath of these deadly attacks.

If the Turkish government resolves to take a tougher stance against ISIL, how will the group retaliate? At the very least, further terrorist attacks in Turkey would harm the country’s tourist industry, which brings in $35 billion in annual revenues. Given the havoc ISIL was able to wreak in Paris, thousands of kilometers away, it could turn neighboring Turkey into a war zone. And yet the Turkish government insists that ISIL is a symptom, not the main problem.

In the eyes of AKP leaders, toppling the Assad regime will facilitate the task of dealing with ISIL. However, Ankara’s game plan is supported by none of the key regional and global powers in this conflict — Iran, Russia, even Turkey’s allies like the U.S. and France — which are mainly concerned with eliminating ISIL, not Assad.

Turkey has no choice but to go along with this strategy, even if — as the sole NATO country to share a border with ISIL — it may have to pay a heavy price indeed. Whatever the future holds for Turkey, there is little doubt that its leadership is anxiously brooding over how to untangle itself from ISIL.

Behlül Özkan is assistant professor at Marmara University and author of the book “From the Abode of Islam to the Turkish Vatan: The Making of a National Homeland in Turkey” (Yale University Press, 2012).

This article was updated to correct the death toll of the Ankara bomb attacks from 128 to 102.