American supporters of the Iraq war could hardly have been pleased when they saw Iranian President Mahmoud Ahmadinejad being given the red carpet treatment during his state visit to Baghdad. Yet they should not have been surprised. That was merely the culmination of a course of events the United States inadvertently set in motion.

From the day that U.S. forces overthrew Saddam Hussein, it was almost certain that Iran would be the main beneficiary. Saddam had been the mullahs’ nemesis for nearly a quarter century. The two countries had waged an extremely bloody war from 1980 to 1988, and Iraq’s Sunni political elite remained Iran’s mortal adversary. Iraq under Sunni rule was the principal regional strategic counterweight to an assertive Iran.

The United States did Tehran a huge favor by removing that political elite, and paving the way for the Shiite-Kurdish alliance that now dominates Iraq’s political affairs. Having taken that step, it does little good now for proponents of the war to whine about Tehran’s expanded influence.

Critics of the war correctly predicted that Iraqi Shiites would adopt a close working relationship with their co-religionists across the border.

That was a danger administration officials should have considered far more seriously than they did before invading Iraq.

Even more embarrassingly, contrary to Bush administration mythology, Tehran’s principal ally in Iraq is not even the radical Shiite cleric Moqtada al-Sadr. Ironically, the forces most loyal to the U.S.-supported government of Prime Minister Nouri al-Maliki are Iran’s primary sources of influence: the Dawa Party, the Supreme Islamic Iraqi Council, and the militias affiliated with both. Tehran’s ties with those two factions are far more extensive than they are with Sadr’s Mahdi Army. Indeed, Sadr is a fairly strong Iraqi nationalist, uneasy about excessive Iranian influence in his country.

The cordial sessions between Ahmadinejad and Iraqi leaders underscore the bankruptcy not only of the Bush administration’s Iraq policy but also of U.S. policy toward Iran. Washington’s original hope was that a secular, democratic Iraq would become a bulwark against both the radical Islamic terrorism epitomized by al-Qaeda and Iran’s brand of Islamic extremism. Iraq would then have become an ally in the American strategy of isolating Tehran. That expectation was always naive, but U.S. leaders have been slow to adjust to political realities in the region. It was only with the greatest reluctance that Washington modified its strategy of isolation and agreed to conduct limited talks with Tehran about stabilizing Iraq.

Even then, the talks have often consisted of little more than U.S. demands that Iran stop supporting radical, violence-prone elements in Iraq.

As much as U.S. leaders might hate to admit it, Iran is a significant player in the Persian Gulf region and a highly influential player in Iraq. No rhetorical overtures against Tehran’s behavior will alter that disagreeable reality. Washington’s only worthwhile option is to engage Iran and seek to establish a more constructive relationship. The Iraq Study Group was clearly moving in that direction with its report in fall of 2006, but the Bush administration brushed aside its recommendations and embarked on the strategically futile surge.

As a general strategy, isolating Iran is doomed to failure, but it is especially fruitless with respect to Iraq’s future. There will be no solution to the problems in Iraq without extensive Iranian involvement.

And Washington will probably not like the outcome even under the best of circumstances. A Shiite-led government in Baghdad may not be an Iranian vassal, but it will have close ties to Iran. And no U.S. policy short of making Iraq an outright U.S. puppet and police state can prevent that outcome.