BAGHDAD — Mahdi al-al-Khafaji drove to Iraq’s capital from a village four hours to the south last week, determined to take part in burgeoning popular protests against the country’s embattled government.

As with his fellow demonstrators, Mr. al-Khafaji was fed up with corruption and poverty in a country with massive oil riches. The rule of law is weak, and his village lacks services. But he has another target in mind for his complaints: Iraqi militias with close ties to Iran.

“Democracy was promised, but there is no democracy with those militias,” Mr. al-Khafaji told The Washington Times at the Oct. 25 protest. “We want Iran out of Iraq.”

Demonstrators have faced a fierce response from security forces, who fired gas canisters at the crowds and left people crying and coughing for blocks from Tahrir Square, one of the main protest areas. Mr. al-Khafaji and many others in the square ran away at times to Saadoun street just to the south for a respite from the violence.

Iran is the barely concealed subtext as Iraq’s federal government deals with some of the most widespread protests in years. The protests began on Oct. 1, a few days after the popular counterterrorism commander Abdul-Wahab al-Saadi was reassigned to the Ministry of Defense. Many Iraqis view Mr. al-Saadi as a hero in the brutal war against the Islamic State, and some speculated that Iran ordered his reassignment. The protests paused in mid-October for the Shiite Muslim Arbaeen holiday but resumed in force on Oct. 25.

Security forces fired live ammunition and tear gas at protesters in Baghdad and across the Shiite-majority south, and at least 250 deaths have been attributed to the crackdown.

The government appeared to respond Thursday to the popular uprising.

Iraqi President Barham Salih announced he would seek a new election law and call for early elections once the law was in place. In a prime-time address, Mr. Salih expressed sympathy for the protesters’ complaints and revealed that embattled Prime Minister Adel Abdul-Mahdi is prepared to resign once political leaders agree on a replacement, The Associated Press reported.

“The current status quo is no longer sustainable,” Mr. Salih acknowledged.

The turmoil has put a fresh spotlight on Iran’s bid for influence with its troubled neighbor, building on links to Shiite militias in Iraq that have long operated outside the formal military system. Many protesters explicitly called on Tehran to stop backing elements in the Iraqi government that they blame for the country’s misery.

Mr. al-Khafaji said he has no doubt about the root of Iraq’s woes. The Iraqi government, Iran-backed militias and Iran itself are all responsible for what he sees as the violent, impoverished state of his country.

“Eliminate this corrupt regime, where there is kidnapping and killing in the streets by militias with Iran,” he said.

Iran, the region’s dominant Shiite Muslim power, is an important economic and political backer of the Iraqi government. Iran provides its neighbor with 40% of its electricity.

The dependence is so deep that even the Trump administration has felt compelled to grant Baghdad waivers to harsh U.S. economic sanctions against the Islamic republic that target Iran’s suspected nuclear program.

Iran also has links to many of Iraq’s powerful Popular Mobilization Forces, mostly Shiite Muslim militias that formed in 2014 to fight ISIS. They now control considerable territory.

Particularly disconcerting for Iraq’s government is the widespread nature of the protests, staged not just in Baghdad, but in Karbala, Najaf and several other cities as well.

‘They’re all Iranians’

The anger at the Iranian government is high. Many of the protesters in Baghdad embrace charges that Iranian nationals are among the security forces suppressing the demonstrations.

“They’re all Iranians,” protester Khadar al-Mohamadawi, with tears in his eyes, told The Washington Times after driving his tuk-tuk away from Tahrir Square because of the choking gas.

Shortly before his interview, men clad in black headed toward the Jumhuriya bridge as gas canisters rained down on the protesters. Many passersby accused them of being Iranian. There is no evidence that Iranian security officials were present, but the theory, though unfounded, is telling of the protesters’ anger at Iraq’s neighbor.

Adding to the anti-Iran sentiment are videos that surfaced Oct. 25 purporting to show Abu Azrael, a muscular social media star who commands one of the Iran-backed militias, after receiving a brutal beating from protesters. One of the main protest chants is “Iran out, out, and Iraq will remain free.”

In the holy Shiite city of Najaf, protesters danced to a patriotic Iraqi song from the Iran-Iraq war of the 1980s. The fact that Shiite Muslims would sing a song from the Saddam Hussein era, in which Shiites were heavily persecuted, shows the extent of anger with the Iranian government.

Iran is a major focus of the protesters’ wrath, but many also say they do not want Saudi Arabia to control the country either. Hassan Ahmed slept in Tahrir Square the night before protests resumed and said Iraqis simply want to control their own destiny.

“We want a government where the people sit in the decision chair,” he said. “Not Iran or Saudi Arabia.”

‘Second-class citizens’

The reasons for the anti-Iran sentiment stem from Tehran’s support for the unpopular Iraqi government, but they go deeper than that. One student protester said Iranians at times seem to be a privileged class inside Iraq itself.

“Iraqis lately have been feeling like second-class citizens in their own country with the way Iraq treats Iranian visitors,” said Karrar, who declined to give his full name.

Iranians do not need a visa or to pay fees to enter Iraq. Thousands come for religious pilgrimages to Shiite holy sites inside Iraq every year.

Pictures of Iran’s supreme leader, Ayatollah Ali Khamenei, are seen all over Iraq, including in Sunni-majority areas such as Mosul. The images only fuel popular resentment, Karrar said.

“The posters filling our streets and institutions with Iranian personalities is also a bothersome sight lately,” he said. “Iraqis have also awakened to the reality that their country is being run by Iranian-backed militias.”

The chaos unleashed by the 2003 U.S.-led invasion has provided a major opening for Iran to increase its influence and economic ties with Iraq. But today, even many Shiite Iraqis accuse Iran of supporting corrupt Iraqi politicians, said Baghdad-based analyst Diyari Salih.

Young Iraqis are not buying into the argument that joining Iran’s anti-Western foreign policy and military operations in Iraq and Syria will help them, he said.

“Shiite youths no longer accept the idea that their job in the axis of resistance is to provide martyrs only,” Mr. Salih said in an interview. “They want an advanced level in the indicators of life and in the efficiency of services such as those that Iranian youths enjoy in Tehran.”

Iran’s ties to Iraqi politicians go right up to Mr. Abdul-Mahdi who, like many others, spent years in exile in Iran. Hadi al-Ameri is another Iraqi political figure with close Iranian ties. He heads the powerful Badr Brigades militia and is a member of the Iraqi parliament, and he fought alongside Iran in the Iran-Iraq war.

Supporters of Iran’s role in Iraq point to the Popular Mobilization Forces’ critical role in the campaign to roll back ISIS, playing a particularly valuable role in the critical battle for Mosul. But many fear the Popular Mobilization Forces ultimately cannot be controlled, Mr. Salih said.

“They point out that Iran supports armed factions operating outside state control,” he said. “These factions put Iraq’s future at risk.”

A ‘strong antagonist’

Despite the security crackdown, protesters have not left Tahrir Square since Oct. 25. The uprising shows no signs of slowing down, but the U.S. should be aware that the anti-Iran sentiment on the streets is not necessarily pro-Western, Karrar said.

“Though there is greater acceptance of Western influence, America remains a strong antagonist to the eyes of the Iraqis,” he said.

Mr. Salih agreed. “These demonstrations are against those who want Iraq to be an Iranian, Saudi, Turkish or American sphere,” he said.

It is unclear what effect the protests will have on the U.S.-led anti-ISIS coalition’s mission in Iraq, but the Islamic State remains active after its 2017 territorial defeat in the country. Its militants are particularly present near the Iraq-Syria border, south of the disputed Iraqi-Kurdish city Kirkuk, and in Mosul, according to Arabic media reports.

The Baghdad government has warned the Pentagon that the U.S. forces President Trump pulled out of Syria cannot relocate to Iraq permanently.

Not all the protesters are hoping to topple the government. Suad al-Jawahiri rode her bike to Monday’ protests and was one of the relatively few but increasing number of women at the demonstrations. She said she doubts street protests on their own will be enough.

“I’m here for my rights and to fight corruption,” Ms. al-Jawahiri said, “but I’m not sure this will succeed.”