ON A sunny October day in 2009 Turkey’s foreign minister, Ahmet Davutoglu, beamed with pride as he inaugurated his country’s consulate in Mosul, an Iraqi city that was once part of the Ottoman empire. “We see you as a part of ourselves; I am your minister,” Mr Davutoglu declared. His words provided an early clue to his neo-Ottoman dreams of Turkey leading a Sunni Muslim arc spanning the Balkans, Central Asia and the Middle East.

Five years on the Turkish consulate serves as the headquarters of the Islamic State (IS), an extremist group formerly known as the Islamic State of Iraq and Greater Syria (ISIS). This fearsomely brutal group raided the building on June 10th, taking all 49 of the consulate’s Turkish staff hostage, including the consul-general, along with two toddlers. Hopes that they would be freed in time for Eid al-Fitr, the start of a holiday marking the end of the Ramadan fast, proved empty. The jihadists are said to be using the Turks as human shields against possible Western military intervention in Iraq. Mosul’s exiled governor, Atheel Al-Nujaifi, whose calls for the Turks to evacuate the consulate fell on deaf ears, says IS is unlikely to let go of them any time soon.

The Mosul debacle illustrates Turkey’s declining fortunes in the region. Until recently Turkey, a NATO member that is in membership talks with the EU, was hailed as a shining example of a Muslim country where Islam and democracy can coexist. But a mix of hubris, pro-Sunni sectarianism and bad judgment on the part of the Islam-inspired Justice and Development (AK) party, has drained the country of its soft power.

The first signs of trouble came with its break with Israel over the killing in 2010 of eight Turks and one Turkish-American aboard the Mavi Marmara, a ship bound for Gaza. There followed a row with Egypt’s generals over the embrace by the Turkish prime minister, Recep Tayyip Erdogan, of the Muslim Brotherhood. But Syria dealt the biggest blow.

Mr Erdogan believed that Syria’s president, Bashar Assad, could be toppled in six months; even less, Mr Davutoglu claimed. Turkey allowed the free flow of arms and rebels, jihadists included, to Syria. (Many of IS’s foreign fighters are believed to have crossed into Syria via Turkey.) IS controls two border crossings with Turkey and has its eyes on another manned by the Syrian Kurds. The Kurds insist that Turkey lets IS fighters use its territory as a back base in their battle against them.

Turkey denies these claims. But they are being examined in Washington, where Turkey’s alleged dealings with jihadists are causing worry. “There is a deep distrust of Erdogan,” says one American official. The prime minister’s most recent diatribes against Israel, comparing Israelis with Hitler, haven’t helped. But America’s leverage is fading. “Unless it came from Obama himself, any criticism will hardly be noticed by Erdogan,” says Henri Barkey of Lehigh University in Pennsylvania.

Pressure from the Americans has compelled Turkey to list IS and Jabath Al Nusra, another extremist outfit in Syria, as “terrorists”. But Turkish officials confess that they cannot fully control the border. Privately, some fret that Turkey may become IS’s next target. Takvahaber.net, a Turkish portal extolling the group’s “victories”, encourages Turks to support global jihad.

Jihad is what Mr Davutoglu once advocated for places like Chechnya and Afghanistan. He called Israel “a geopolitical tumour”. These and other pronouncements by Mr Davutoglu were dug up by Behlul Ozkan, a political scientist at Istanbul’s Marmara University who scanned more than 300 articles penned by his former professor in the 1990s. But Mr Davutoglu considers IS to be his ideological foes. “He is more in line with the Muslim Brotherhood,” says Mr Ozkan.

Despite his recent setbacks there is no sign that Mr Davutoglu will be ditched. He is “likely to continue to drive Turkish foreign policy so long as AK remains in power,” says Aaron Stein, an analyst at RUSI, a London-based think-tank. Moreover, there are strong rumours that Mr Erdogan, who is on course to become Turkey’s first popularly elected president in a first round of balloting on August 10th, has picked Mr Davutoglu to succeed him as prime minister. With luck, the Mosul disaster will banish his Ottoman fantasies. As yet, however, there is no sign of that happening.