BAGHDAD — When the Iraqi military battled Kurdish forces this week to reclaim the contested city of Kirkuk, the spectacle of one American-backed ally fighting another with American-supplied weapons was not the only incongruous sight.

Another was the United States turning its back on a crucial ally in the fight against the Islamic State, the Kurds, as Washington’s goals aligned with those of a regional nemesis, Iran.

While the military action in Kirkuk on Monday and Tuesday was carried out under the banner of the Iraqi military, the ground forces included Iranian-backed Shiite militias.

American officials, including President Trump, insisted that the United States was not taking sides in the dispute, but some analysts say that the United States approved the Iraqi plan to enter Kurdish-held areas and that Iran helped broker the agreement with a Kurdish faction to withdraw its fighters from Kirkuk, allowing the Iraqi forces to take over largely unopposed.