Mullah Rahim Hajin and 50 of his men are holed up in a mud brick fortress just 10 kilometres from the Pakistani border, on the front line between local militias and soldiers allied to the Islamic State (Isis). Hajin, in his 50s, wears the traditional turban reserved for Afghani elders as he stands in the desert near a checkpoint, surrounded by the most loyal of his men.

Rahim is from the Shinwari Pashtun tribe, which recently joined the armed struggle against Daesh's offensive in Khorasan. On the walls of the fortress are printed pictures of the group's bravest fighters. "We are not a militia: we are all local sons, fathers and brothers, whose duty is to protect our families," he says.

Handpicked three months ago by local elders, Mullah Rahim has fought Daesh alongside Afghan forces. "They are our brothers and we are proud to fight on their side," he says. As many as 140 of his men have now joined the local police, Achin district governor Haji Ghalib Mujahid confirms: "With them we have 280 local police officers and 80 national army soldiers that are ensuring the governmental control of 80% of this district."

Still, the fear of new attacks remains high. Behind the mountains in the Tirah valley of Pakistan, members of the Khorasan faction of the Islamic State lie in wait for a new outbreak of violence. Meanwhile, unlike members of the Afghan army and police – who receive a salary of $120 a month – Mullah Rahim's men fight for free, are largely un-trained and have little stocks of weapons and vehicles.

"We are Afghans, we know how to protect our home from the brutality of foreigners," Rahim claims.

Despite a lack of formal training, many of these men have fought in the past against the Taliban, backed by the US. Nowadays, they receive support from the deputy speaker of Afghan parliament, Haji Abul Zahir Qadir. Their emnity with the Taliban continues due to alleged links between the Shinwari tribe and the opium and heroin trade.

Isis activity in Afghanistan dates back to 2014, but significant military operations did not begin until last April, when Isis leader Abu Bakr al-Baghdadi branded Taliban founder Mullah Omar "a fool and an illiterate warlord". The two insurgent groups then declared war on each other.

Taliban leader Mullah Akhtar Mansour, who took over after Mullah Omar was confirmed dead in 2015, has in called on Isis to avoid clashes between the groups by joining forces against foreign occupations, but to little avail: Isis has recruited hundreds Taliban fighters over the past few months.

The militia fortress in Desarak village
The militia fortress in Desarak village Laura Cesaretti

In Achin district, the arrival of Isis's Wilayat Khorasan, which incorporates both Afghanistan and Pakistan, was welcomed by some at first. Many hoped that they would push back the Taliban presence in the area, disliked especially by the same Shinwari tribe to whom the militia belong.

Isis sources say 283 members of the tribe have pledged alliance since the beginning of their offensive due to enmity with the Momand tribe, the other Pashtun tribe present in the area, to whom many Taliban members belong. However, when Isis insurgents set fire to heroin factories in the area, conflicts between the Shinwari and Isis Khorasan fighters also arose.

Local sources state that around 70 heroin-producing facilities are located in Achin district. The close border with Pakistan has long made the area a convenient drug transit and business route. The Taliban used to turn a blind eye to these criminal activities by imposing a high tax, called ushr, to the smugglers.

After the US invasion this tax was integral to financing the Taliban, but angered local drug traffickers. Islamic State members, instead, started a violent campaign against all this drug industry. With time, this brutal engagement affected also the local population, causing the death and the terrorization of many villagers.

"They have killed civilians by cutting off their heads", says Mullah Rahim. "We are ready to depose the army as soon as will be sure that this would never happen again."

In Achin, his men drive through town on the backs of pick-up trucks as elders and children wave to them. For now, the district centre of Achin is back to normal, with the shops and central bazaar open and people on the streets. The district governor appointed six months ago, Haji Ghalib Mujahid, is enjoying the temporary victory.

He himself represents the bloody history of Afghanistan. A former mujahedeen against the Soviet occupation, he was detained in Guantanamo by Americans under false accusations, he claims. When released, he began to work for the Afghan government. His entire family was killed by the Taliban in a bomb attack at a family funeral.

The threat from both the Taliban and IS rumbles on in the lawless district close to the Pakistani border. Even with its complex – if not chaotic – patchwork of loyalties and ideologies, Nangarhar was known as a model province for some years since 2001 even as the Taliban continued to operate in the area. Mullah Rahim and his men represent an attempt to restore that stability once again.

Laura Cesaretti is an Italian freelance reporter based in Afghanistan. Previously she has been working in Turkey and Lebanon, covering the Syrian humanitarian crisis.

Silab Mangal is an Afghan freelance journalist specialised in security affairs.