When the United States said this week that American forces in Iraq faced threats from Iranian “proxies,” it was referring to the armed groups that helped fight the Islamic State and have bedeviled Iraq ever since.The Iraqi armed groups, some with ties to Iran, have a footprint in every Iraqi province. Whether they function as Iranian proxies, however, is far from settled.“The word ‘proxy’ implies that these are tools of Iran, and they aren’t,” said Anthony H. Cordesman, a national security analyst at the Center for Strategic and International Studies.“You have a range of groups in Iraq’s Popular Mobilization: Some are Sunni, some are pro-Iraqi government, some have ties to the Quds force and the Islamic Guard,” he said.The question is further clouded by the fact that these groups are recognized and funded by the Iraqi government.This week, the United States ordered an aircraft carrier and bombers to the Persian Gulf in response to what it termed as threats from the groups. On Tuesday, Secretary of State Mike Pompeo made an unannounced trip to Iraq to press its leaders about what he said were increased dangers to Americans there from Iran’s forces and allies.There are roughly 30 of the militias, known as the Popular Mobilization Forces, with at least 125,000 active-duty fighters.Members of the pro-Iranian militia Harakat al-Nujaba watched an address by Hezbollah’s leader, Hassan Nasrallah, on a screen during a rally near Beirut, Lebanon, last year.CreditNabil Mounzer/European Pressphoto AgencyMembers of the pro-Iranian militia Harakat al-Nujaba watched an address by Hezbollah’s leader, Hassan Nasrallah, on a screen during a rally near Beirut, Lebanon, last year.CreditNabil Mounzer/European Pressphoto AgencyTheir relationships with Iran vary widely, according to experts and government officials in Iraq and Washington. Some Popular Mobilization groups keep their distance from Iran while others — including some of the most powerful — are deeply intertwined with it.Now that the fight against the Islamic State has dwindled, the problem facing Iraq is what to do with these groups. While there has been talk of having them disband and disarm, only a couple of them seem willing to do so.Although the militias have been absorbed into the Iraqi security forces, they are not under the command of either the Defense or Interior Ministries. Instead, they enjoy a special status, reporting to the prime minister.Some of the groups seem relatively benign and carry out almost exclusively local responsibilities, providing policing services where the police are in short supply.However, others are corrupt, behaving like mafias, and several have been accused of human rights abuses. And while they report to the prime minister, it is not clear that anyone really can restrain them.“If they have armed wings and are corrupt, no one can control them,” former Prime Minister Haider al-Abadi said in an interview this year.A major concern among some officials is that, much like Iran’s Islamic Revolutionary Guard Corps, they will go into business, but with the unfair advantage of having armed men behind them and the implicit protection of senior figures in the Iraqi government.“In Iraq if you don’t put controls on these groups, you will have these guys morph into networks that will range from semi-criminal entities to politically predatory forces that would act as a state within a state,” said Alex Vatanka, a senior fellow at the Middle East Institute.Fighters with a People’s Mobilization militia at the Iraq-Syria border in northwestern Iraq in 2017.CreditSergey Ponomarev for The New York TimesImageFighters with a People’s Mobilization militia at the Iraq-Syria border in northwestern Iraq in 2017.CreditSergey Ponomarev for The New York TimesIt is the four or five groups with the closest ties to Iran that are seen as exercising unauthorized power. Some run kickback schemes on a local level, using coercion to force business people to give them a piece of the action or compel citizens to use their services.Many of these groups have large numbers of representatives in the Iraqi Parliament, where the power to designate ministers is divided among the political blocs. If a bloc or a party controls who becomes a minister, they have a chance to influence who gets valuable contracts or jobs.These groups also can act as a lobby for Iranian interests within the Iraqi state.Senior Iraqi government officials worry privately about the influence of the groups that have proved closest to Iran and are impervious to efforts to bring them under the government’s control, but the officials are generally reluctant to speak publicly about it.The Defense Ministry was angry when some of the Popular Mobilization’s brigades moved to the Syrian border in November, taking up crucial positions, but the ministry worked out a way of avoiding a confrontation with them.Similarly, soon after the United States Treasury Department announced in March it was listing one of the Popular Mobilization groups, Harakat Hezbollah al-Nujaba, as a foreign terrorist organization, the Iraqi government made clear it disagreed.Prime Minister Adel Abdul Mahdi did not defend the group by name — al-Nujaba has proved difficult for the Iraqi military to work with at times — but he did support the Popular Mobilization groups.“The Americans can make the decisions they want, but the Americans see things differently from the way we do, and our attitude toward the Popular Mobilization is well known and clear,” he said in March. “We respect all of the groups of the Popular Mobilization that made sacrifices.”The sacrifices he was alluding to were largely made from 2014 through 2016, when the Islamic State swept across northern Iraq with little resistance and was moving fast toward the capital. Urged by a call in June 2014 from Grand Ayatollah Ali al-Sistani, Iraq’s influential Shiite spiritual leader, for volunteers to defend their nation, young men and old formed a pickup army.Popular Mobilization Forces marching in Baghdad last year.CreditHadi Mizban/Associated PressPopular Mobilization Forces marching in Baghdad last year.CreditHadi Mizban/Associated PressIran sent some Iraqis who were fighting with them in Syria, on behalf of President Bashar al-Assad’s Syrian Army, back to Iraq to confront the threat on their home turf.In places where the Iraqi Army collapsed in the face of the Islamic State, the Popular Mobilization Forces went in: They secured roads, fought the Islamic State and cut off their escape routes. Iran helped the Popular Mobilization acquire weapons and supplies, but gradually that role was taken over by the Iraqi government.At the time, the Popular Mobilization groups “did a lot of good and sacrificed with their blood” to help save the country from the Islamic State, said Wafiq al-Hashimi, a political scientist at the Iraq Strategic Studies Group.However, in areas where they defeated the Islamic State, some militias took over the extremists’ illegal activities, enriching themselves but doing little for local communities. These groups, most notably in northern Iraq, fought Iraqi government forces as recently as last year to hold on to their oil smuggling business. They ultimately lost, but still have bases near the now-capped oil wells.At least a couple of the Popular Mobilization groups are led by figures who attacked American forces in the years after the United States invaded Iraq, making any threats against United States forces and civilians in the region particularly worrying to officials.One of those groups is Asaib Ahl al-Haq, led by Qais al-Khazali, whom American officials accused of masterminding an audacious attack against Americans in Karbala, Iraq, in 2007. More recently, the group was accused by rights groups of the extrajudicial killings of Sunnis during the fight against the Islamic State. In recent months, it has been criticized for demanding that business owners in northern Iraq give it a cut of any business they are involved in. The group has denied the accusations against it.Similarly inimical to American interests are the armed groups and political party linked to Moktada al-Sadr, a cleric whose supporters have the largest number of seats in the Iraqi Parliament. Although Mr. al-Sadr has recently kept Iran at arm’s length, he has taken a strongly nationalist stance. He often ends up on the same side as Iran when it comes to the United States, since he, too, would like to see American soldiers leave Iraq.For Iraqi politicians, who want to build their country and improve life for its citizens, the pressure from Iran on Iraq presents a daunting challenge. At least some of that pressure is channeled through the Popular Mobilization, said Mr. al-Abadi, the former prime minister.“It’s a very dangerous cocktail of militia and mafia,” he said.