This was not the first time consular staff in Mosul has come under attack. In September 2013 and as recently as May, Yilmaz was attacked by unknown assailants who set off remote-controlled explosive devices as he rode in his armored vehicle in Mosul. He was unharmed, but it was a clear warning that the consulate had become a target.

On June 6, the governor of Mosul, Atheel al-Nujaifi, put in an emergency call to Kareem Sinjari, the interior minister of the Kurdistan Regional Government (KRG) in northern Iraq saying that ISIS was about to take over the city. Sinjari swiftly spread the word, a full five days before the attack occurred. It is unthinkable that the Turks were not aware of the danger. Yet, they apparently did not feel threatened enough to evacuate the consulate. Indeed, as recently as June 10, Turkey’s Foreign Minister Ahmet Davutoglu declared that there was no threat to Turkey’s Consul General Ozturk Yilmaz and his staff. Davutoglu has since changed his tune, now saying that the security environment to travel by land to Erbil, the Iraqi Kurdish capital, had rendered evacuation impossible. Never mind that it’s just a 40-minute drive from Mosul. In the worst-case scenario, Turkey could have used helicopters to evacuate the personnel. Turkey has around 2,000 troops stationed on the Iraqi side of the Turkish-Iraqi border, nominally there to chase Kurdistan Workers Party (PKK) fighters if need be, and they have helicopters.

As Turkish leaders scramble to find a way out of the crisis, details of the security lapses that led to the storming of the consulate are beginning to emerge. Unless the hostages are released unharmed, Turkish Prime Minister Recep Tayyip Erdogan could face a political crisis of a scale that might yet torpedo his candidacy for the August presidential race.

The seizure of 49 staff members of the Turkish consulate in Mosul by Islamic State of Iraq and al-Sham (ISIS) militants has refocused attention on Turkey’s failing Middle East policy and exposed embarrassing flaws in its handling of diplomatic security.

“It is unbelievable that he was sent back [to Mosul],” a Foreign Ministry official who declined to be identified by name grumbled to Al-Monitor.

Why was Turkey targeted?

Some Turkish officials who spoke to Al-Monitor on condition of anonymity clung to the tired conspiracy theory that Syria’s President Bashar al-Assad was using ISIS to get back at Turkey. And why would Assad back a group that has brought one of his chief allies, Iraq’s Shiite Prime Minister Nouri al-Maliki, to his knees? No answer.

Aymenn Jawad Al-Tamimi, A Shillman-Ginsberg Fellow at the Middle East Forum who closely monitors ISIS, has a different explanation. The raid on the Turkish consulate “fits into a broader pattern of ISIS taking foreigners hostage in the hopes of securing lucrative ransoms,” he told Al-Monitor in an interview.

A more troubling possibility is that the raid was a warning to Turkey of the consequences it is likely to face should it tighten the screws on jihadist groups moving across its borders. ISIS has long made clear its disdain for Erdogan, whom it labels an “apostate.”

Just days before the raid, Turkish officials leaked details of what Murat Yetkin, a columnist for the Turkish daily Radikal, heralded as “an intelligence-sharing operation on foreign jihadist fighters in Syria” between Turkey and the United States. “It is poised to be the biggest of its kind,” Yetkin predicted. The news coincided with Ankara’s decision, after much foot dragging, to formally declare Jabhat al-Nusra a terrorist organization. (ISIS was labeled thus in September 2013.) It is worth noting that the twin bombings in Reyhanli, which many believe were the work of ISIS, occurred shortly before Erdogan met in Washington with US President Barack Obama. Alleged Turkish support for Jabhat al-Nusra was said to have dominated the talks.

What are Turkey’s options?

Turkey has said it will “take all necessary measures” to free the hostages. But is it unlikely to take military action of any kind, even after the hostages are free.

Turkish officials who spoke to Al-Monitor on condition of anonymity acknowledged that their sole option for now was to negotiate with ISIS. The officials denied that ISIS was seeking a ransom or the release of any ISIS prisoners. They did reveal that a deal with ISIS to free the hostages had been reached the day there were taken, only to collapse hours later.

“We agreed that they would be handed over in the [Iraqi] Kurdish-controlled territory. Then suddenly their tone grew more aggressive and they demanded that the handover take place at the Turkish border.” The official said that it was “obvious” that there were “different” factions and that the “hard-liners” had prevailed. ISIS presently controls two border crossings with Turkey (Akcakale, facing Tal Abyad, and Karkamis, facing Jarablus). Both remain sealed on the Turkish side, presumably disrupting the flow of weapons and other supplies to ISIS.

There is widening speculation that Turkey may now feel compelled to forge an alliance with the Syrian Kurds, who are locked in a bloody turf battle with ISIS. Salih Muslim, the co-chair of the Democratic Unity Party, the most influential Kurdish group on the ground, has repeatedly called on Turkey to join forces against ISIS. Turkey has spurned his calls, saying the Syrian Kurds need to sever their ties with the Assad regime and join the opposition if they want to do business with Ankara.

Is there any softening of that position? Not according to the Turkish officials who spoke to Al-Monitor. “We gave them countless chances, and they broke their promises each time,” claimed one of the officials. “They continue to support Assad.” The more likely scenario is that the government will step up its support for other armed opposition groups like the Salafist Ahrar al-Sham, continuing in effect to feed the Islamic radicalism that now threatens Turkey.