The urgent fight to keep Islamic State forces­ from taking over more of Iraq has led the Obama administration to tolerate, and in some cases even approve, things it once would have loudly protested.

When Iraqi Shiite militias, backed by Iran and long branded illegal by the administration, retook the town of Amerli from the Sunni Muslim militants last week, U.S. officials breathed a sigh of relief.

Qassem Suleimani, the head of the Iranian Revolutionary Guard Corps’ Quds Force and usually described as an arch­enemy of the United States, reportedly was present during the battle and was seen days later in an Internet-posted photo shaking hands with a militia fighter.

Farther north, Kurdish fighters have occupied the oil-rich city of Kirkuk, a prize the Kurds have long claimed but which lies outside the borders — recognized by both Baghdad and Washington — of Iraq’s semiautonomous Kurd­i­stan region. Far from insisting the fighters withdraw, the administration is glad that someone is defending the city from the Islamic State.

Such legal and policy niceties have become a luxury in the battle to push back the militants whom President Obama on Friday called “a savage organization” that “poses­ a significant threat” to the United States and its allies.

It is not, as one administration official said with significant under­statement, an ideal situation, and there is widespread recognition that facts are being created on the ground that are likely to cause problems in the future.

But for now, the existential battle being waged in Iraq is one that has made at least indirect confederates of forces­ that are neither allies nor partners, nor often even on speaking terms.

While the administration has acknowledged discussing the Iraqi crisis with Iranian officials on the margins of separate talks about Iran’s nuclear program, “we do not coordinate military action or share intelligence with Iran and have no plans to do so,” National Security Council spokeswoman Bernadette Meehan said Friday.

“At the same time, we have been clear that ISIL,” one of several acronyms for the Islamic State, “represents a threat not only to the United States, but also — and most immediately — to the entire region. We believe that all countries, regardless of their differences, should work toward the goal of degrading and ultimately defeating ISIL,” Meehan said.

Asked whether there was a role for Iran in the international coalition the administration is forming to fight the militants in Iraq and ultimately in Syria, a senior administration official this week said, “I don’t know.” But, the official acknowledged, “they already . . . have a role on the ground.”

Iranian contributions have extended beyond weapons and advisers to the Shiite militias. Despite Tehran’s concerns about separatism within its own Kurdish community, it “was the first country to provide us with weapons and ammunition” to fight the militants, Kurdish President Massoud Barzani said late last month during a visit of Iran’s foreign minister.

Iran is also believed to have conducted airstrikes against the Islamic State, U.S. officials said.

The United States has vied with Iran for influence in Iraq ever since the majority Shiite government was installed after the 2003 U.S. invasion that overthrew Sunni leader Saddam Hussein. Iran was accused of supplying the improvised explosive devices, called IEDs, to the militias that used them to blow up hundreds of American soldiers during the previous decade.

In recent years, the militias have laid low as an organized force. But when the Iraqi army fled northern cities in advance of the Islamic State blitz through the country this summer, they quickly re­emerged and entered the fight. U.S. protests were largely pro forma.

When former Iraqi prime minister Nouri al-Maliki stepped down under U.S. pressure last month, Iran signaled its approval by congratulating his successor and calling for an inclusive government.

The strong administration preference is for Shiite militia members — as well as Sunni tribesmen in western Iraq — to join the Iraqi security forces­ and fight the militants under the government’s banner. But U.S. officials, who were not authorized to discuss the administration’s strategy on the record, said they would take what they could get until the militants are driven back.

The United States is not the only actor on the ground that finds the situation uncomfortable. While the administration credited U.S. airstrikes with helping drive the Islamic State out of Amerli, militiamen on the ground restated their enmity toward the Americans and said the strikes were inconsequential in the victory they had won.

Iran’s Fars News Agency said Friday that the idea that U.S. action had been decisive in Amerli was a figment of the American imagination. “The West has launched media hype to show the U.S. as the savior of Iraq,” the agency said, quoting an Iranian military source.

When the BBC reported Friday morning that Iran’s supreme leader, Ayatollah Ali Khamenei, had approved cooperation with the U.S. military against the Islamic State, senior government officials quickly denied it. “It’s impossible,” Esmail Kowsari, deputy chairman of the Iranian parliament’s National Security and Foreign Policy Commission, told Bloomberg News.

“We don’t need the U.S.,” said Kowsari, a former Revolutionary Guards commander. “We know how to take care of [the Islamic State] ourselves.”

At Friday prayers, senior Tehran cleric Ayatollah Seyed Ahmad Khatami described the militants as a creation of the United States and other Western powers, Fars reported.

In the Kurdish region, where the United States has long advocated a referendum on the future of Kirkuk and other contested areas, the gains of the local fighters, known as pesh merga, are celebrated no matter where they occur.

The administration has not publicly endorsed the occupation of Kirkuk and its adjoining oil fields, but neither does it want the Kurds to abandon the territory they have seized while the Iraqi army does not have the capability to protect it from the Islamic State.

Resolution of the issue will have to wait for another day. By then — assuming the militants are eventually driven out of Iraq — the weapons flowing to the pesh merga from the United States, Europe and Iran will have made them a far more formidable force to back the regional government’s claims than they were before the current crisis.