The 25 men who gathered last week in a poor enclave of this ancient city bore the scars of a lifetime of war. One lost four fingers fighting Taliban militants. Another lost his right leg fighting the Soviets. Now, seated in a bare room on a cold morning, they declared readiness to make even greater sacrifices against a new enemy: the Islamic State.

To accomplish that, they have taken the law into their own hands.

The men, mostly former mujahideen commanders, have created Afghanistan’s newest militia — Margh, or “Death,” in the local Dari language. It’s so named because they vow to fight to the end to prevent Syria- and Iraq-based extremists from establishing a foothold in their country.

[More than 10,000 Afghan civilians died or were injured in 2014, U.N. says]

“We are ready for martyrdom,” proclaimed Haji Mohammad Mahabiyar, their leader, as his comrades nodded in agreement.

The danger posed by the Islamic State to Afghanistan is minimal at the moment. Yet that hasn’t stopped fears from swirling through the nation and the corridors of power. American and Afghan officials say they view the group as a serious potential threat. Now, the specter of the Islamic State is driving vigilante behavior, particularly by ex-mujahideen fighters who feel sidelined by the government.

The Margh militia is the latest of the many irregular armed groups brazenly forming across the nation, seldom challenged by authorities even as President Ashraf Ghani has vowed to disband them. With most U.S. and NATO forces gone and Afghanistan’s security forces struggling to fill the void, such renegade militias pose a major obstacle to Ghani’s promise of creating a new Afghanistan where the rule of law is respected.

In the past, militias were fueled by ethnic rivalries, warlords or a desire to oust the Taliban. Now, human rights activists and analysts worry that the Margh militia — whose masked fighters wear ninja-like outfits in the red, black and green colors of the Afghan flag and which claims to have 5,000 fighters — could portend the rise of another generation of unofficial armed actors.

The militia has yet to fight a battle. But the concern is that it will unjustly target people it suspects of ties to the Islamic State, even if that group never takes root here, or that it could become a tool of regional strongmen or neighboring powers with other agendas.

[Pakistani, Afghan officials: Taliban is willing to enter into peace talks]

“The experience we’ve had in the past in our country, without any doubt, is that such an illegal armed group creates problems for the people,” said Qazi Sayed Mohammad Sami, head of the Afghanistan Independent Human Rights Commission in this northern provincial capital. “We don’t know who is supporting them or who they are working for. This is our fear.”

Since the war began in 2001, many pro-government militias have operated with little oversight or accountability. As they fight the Taliban, they have committed ­extrajudicial killings, rapes, abductions and other abuses, according to human rights activists.

To be sure, the paramilitary forces are nowhere near as lethal as the Taliban — but they are getting deadlier. Last year, they killed 53 civilians and injured 49 others, an 85 percent increase in casualties from 2013, according to a recent U.N. report that urged the government to promptly demobilize militias.

“The Afghan security forces are suffering thousands of extra casualties every year now that the international forces have mostly pulled back from the battlefields,” said Graeme Smith, Afghanistan analyst for the International Crisis Group, “so there’s a strong temptation to raise pro-government militias to serve as a buffer against the rising insurgency.”

Fueling the fire

Mahabiyar’s mud-walled house, where the Margh militia’s founders had gathered, is not far from the Blue Mosque, which some Muslims believe is among Islam’s most sacred sites. Over steaming cups of green tea, the men railed against the Islamic State.

“They are not real Muslims,” one thick-bearded commander said.

“They are burning people alive!” another declared, referring to the video released earlier this month by the Islamic State that showed the immolation of a captured Jordanian pilot, Lt. Muath al-Kaseasbeh.

A few weeks earlier, they had sat in this room and created their force. They didn’t seek permission from the central government or local authorities. It was around the time the Islamic State — also known as Daesh — announced its expansion to Khorasan, an area that encompasses Afghanistan and Pakistan.

Last week, Gen. John F. Campbell, the top U.S. commander here, told the Senate Armed Services Committee that the Islamic State’s presence in Afghanistan is “nascent.” There has been some recruiting, he said, and a few disgruntled Taliban forces have claimed allegiance to the Islamic State to gain resources or media attention.

His comments came three days after a U.S. airstrike in the southern province of Helmand killed Mullah Abdul Rauf Khadim, a former Guantanamo Bay detainee and Taliban commander who had aligned with the Islamic State. It was the first known targeting of an Islamic State operative by the United States in this region.

“We’re all driven to prevent Daesh from establishing a meaningful foothold in Central Asia,” Campbell said.

For the Margh militia, the potential threat is local. In neighboring Sar-e Pol province, a few Taliban factions have replaced their white flag with the black Islamic State flag and are actively recruiting, militia members there said.

[For 50 years, one American’s life has traced Afghanistan’s — bin Laden and all]

Many Margh fighters are ethnic Hazaras and Shiite Muslims, including Mahabiyar, a wiry 40-year-old. Some Afghan officials speculate that the militia is backed by Iran, which supports the Shiite militias in Iraq fighting the Sunni Islamic State.

But the militia’s leaders insist the driving force here is not sectarian. Their members also include ethnic Tajiks, Uzbeks and Pashtuns, who are all Sunni. They share outrage over the Islamic State’s brutality — and a historic dislike of foreign invaders.

“Daesh is not just against Shiites. In Iraq, they have killed more Sunnis than Shiites,” Mahabiyar said. “They are against all human beings. For Afghans, no matter what ethnic group they are, once they see foreign invaders, they will be united as they did during the Russian invasion.”

What’s also fueling them is a sense that the government is incapable of protecting them and their families. Militia members criticized former president Hamid Karzai as well as Ghani for failing to stop the growth of the Taliban.

“In the last 13 years, there have been so many killings, so many kidnappings, so much lawlessness. And the Taliban was not destroyed,” Mahabiyar said. “The people cannot sit and do nothing. They don’t want to wait for another terrorist group to base itself in Afghanistan.”

The militia, he added, will stand by the government. But its members want to fight outside the security forces because, they say, they would be more effective that way. And they want Afghan forces to arm them.

A senior Afghan Defense Ministry spokesman, Brig. Gen. Dawlat Waziri, dismissed the militia as nothing but a “group of villagers concerned about Daesh.” The security forces, he said, have no intention of arming the group. But he added that Afghans have a right to use weapons to defend themselves.

“There are no militias in Afghanistan,” Waziri said.

Regaining relevance

The Margh militia also represents another development: Amid the growing fears of the Islamic State, former mujahideen who fought the Soviets are sensing an opportunity to become relevant again.

For the past 13 years, many have felt ignored by the government — deprived, they say, of political and military appointments. But their legacy is mixed: While they were praised for fighting the Soviets and the Taliban, most Afghans haven’t forgotten that their grab for power plunged the country into a brutal civil war in the early 1990s.

On Sunday, Aburrab Rasul Sayyaf, a powerful Islamist politician and anti-Taliban commander, publicly blasted the government for isolating the former guerrillas and vowed to fight the Islamic State.

“If Daesh arrives to our doors, you’ll be knocking on the doors of the mujahideen once again,” said Sayyaf, speaking at a rally to commemorate the 26th anniversary of the departure of the last Soviet troops.

If the government doesn’t arm it, the Margh militia will find other ways to acquire weapons, members said. Some were seated with Kalashnikov assault rifles. One commander said his men fought the Soviets by hurling molotov cocktails made from cans, then seized their weapons to use against them.

Others said they would use knives, swords, shovels and axes — any tools they can find — against the Islamic State.

“Their graveyard will be Afghanistan,” Mahabiyar vowed.