IN OCTOBER 1832 Russian soldiers besieged the village of Gimry (pictured) in the mountains of Dagestan in an effort to capture Gazi-Muhammad, the first imam of the Caucasus Imamate, who had defied their rule. He was killed, but his follower, Imam Shamil, jumped over the line of Russian bayonets and escaped. Ever since then, Gimry has been a symbol of defiance and a stronghold of Islamic rule.

In the autumn of 2014 Russian soldiers again besieged the village. They were trying to capture Magomed Suleimanov, a native of Gimry who had been proclaimed emir of the Emirate Caucasus, an al-Qaeda-linked insurgency launched in 2007. The soldiers sacked a neighbouring settlement, forced out its population of 1,000 and looted their houses. Mr Suleimanov escaped, but Gimry remains surrounded by Russian soldiers; only residents are allowed in.

Yet the Russian army, it seems, is fighting yesterday’s war. While it is still trying to catch Mr Suleimanov, his insurgency seems to be on its way out. “The Emirate Caucasus is dead,” says Abdurakhim Magomedov, an aged leader of the puritanical Salafi movement from the village of Novosasitli. “It has not been effective.”

The Emirate Caucasus has been replaced by something even nastier: Islamic State (IS). Up to 2,000 young men from Chechnya and Dagestan may be fighting for IS, according to estimates by Russian security experts. Several commanders from the Emirate Caucasus in Chechnya and Dagestan have switched their allegiance to the IS leader, Abu Bakr al-Baghdadi.

Young men are drawn to IS by its perceived strength and success, says Abas Makhmudov, an ex-member of the shura, or Islamic council, of Chechnya and Dagestan. Others speculate that the risks of fighting in Syria are less awful than at home: a young jihadi may be killed, but his killers will not be able to threaten his family back in Dagestan or Chechnya. Mr Makhmudov opposes IS, yet his own son was recently killed fighting for the group in Syria. “I tried to stop him, but he was enticed by his friends and the images on the internet—particularly the ones of atrocities by the Assad regime,” he says.

What baffles Mr Makhmudov is how his son, who had a criminal record, obtained the Russian passport needed to travel abroad—even after he alerted the authorities to his son’s intentions. It is even less clear how Nadir Medetov, a radical preacher who had been under house arrest in Dagestan, made his way to the Middle East, where he swore allegiance to IS. In a recent interview Nikolai Patrushev, the secretary of Russia’s Security Council, claimed it would be impossible to stop the flow of recruits to IS. Coming from an official of the security apparatus that sealed off the entire region ahead of the 2014 Winter Olympics in Sochi, that sounds disingenuous. Most people interviewed for this article who have had contact with those who have gone to Syria suggest that Russian security services have been complicit. “They are certainly not trying to stop them,” says Magomedrasul Saaduev, the chief imam of the central mosque in Makhachkala, Dagestan’s capital. Formally, Russia supports the regime of Bashar Assad and deems IS illegal. It recently outlawed the participation of Russian citizens in armed conflicts abroad with aims that “contradict the interests of the Russian Federation”. (The caveat is presumably meant to distinguish IS fighters from Russians fighting in eastern Ukraine.) However, Russia may hope that letting jihadists leave the country is good riddance. Insurgent activity in the North Caucasus has certainly gone down. The chances of IS militants returning are slim; Russia does, in fact, tightly control its borders. Yet Akhmet Yarlykapov, a Dagestan expert at the Russian Academy of Sciences, says the tactic is short-sighted. Russia itself is faced with a major threat from IS: it recently claimed the entire territory of Caucasus as one of its provinces (see article).

Over the past two years, the regional commanders of the Emirate Caucasus pledged not to target civilians and ruled out the use of female suicide bombers. But switching allegiance to IS may entail employing its methods, says Mr Yarlykapov.

As a preventive measure, the authorities are piling pressure on anyone who practises Salafism. Ikramudin Aliev, who was fired as a co-ordinator of the pro-Kremlin youth movement in Dagestan for growing a beard, says the authorities are trying to shut down his Salafi mosque by planting weapons and drugs on its clerics. Ziyautdin Uvaisov, a young Salafi imam who opposes IS, argues that instead of letting people like him do his job and educate Muslims, the authorities are radicalising them and pushing them into the hands of IS or the local insurgency.

A recent report by Human Rights Watch found that the use of extra-judicial harassment is widespread. Yet while the state can apply force, it can scarcely supply social services or justice. Magdi Kamalov, the editor of Chernovik, an independent newspaper, says the presence of Russian power in Dagestan is mainly decorative. “We see more and more people coming to us for justice,” says Mr Saaduev, the imam of the main mosque in Makhachkala, who adheres to the state-endorsed Sufi creed.

Just a few years ago, Dagestan’s Salafi and Sufi leaders were on the verge of religious conflict. Now they are uniting in the face of twin threats: IS recruitment and the Russian government’s lawlessness. The Emirate Caucasus might be losing its grip. So, however, is the Russian state.