If visitors to Baghdad knew nothing of Iraqi politics, they could be forgiven for thinking that the trim-bearded, green-uniformed man whose larger-than-life photo is everywhere in the Iraqi capital was Iraq’s president.

Along the boulevard that tracks the Tigris River and inside the Green Zone, the seat of Iraq’s government, the likeness of Maj. Gen. Qassim Suleimani towers above roundabouts and stands astride medians. The last person to be so glorified was Saddam Hussein, the dictator deposed and killed in the American-led invasion of Iraq that began almost exactly 20 years ago.

But Mr. Suleimani was Iranian, not Iraqi.

The commander of the Quds Force, the external arm of Iran’s powerful Revolutionary Guards Corps, he achieved near-mythic status in Iraq as an influential force who helped bind Iraq and Iran together after the invasion. It was thanks in large part to Mr. Suleimani, whom the United States assassinated in Iraq in 2020, that Iran came to extend its influence into almost every aspect of Iraqi security and politics.

That, in turn, gave Iran outsize influence over the region and beyond. Tehran’s rise exposed the unintended consequences of Washington’s strategy in Iraq, analysts and former U.S. officials say, and damaged the United States’ relationship with its regional allies.

The invasion “was the original sin,” said Emile Hokayem, a senior fellow for Middle East security at the International Institute for Strategic Studies, a British think tank. “It helped Iran bolster its position by being a predator in Iraq. It’s where Iran perfected the use of violence and militias to obtain its goals. It eroded the U.S.’s image. It led to fragmentation in the region.”

The U.S. State Department declined to comment on the impact of the war in Iraq.

“On Iraq specifically, our focus is on the 20 years ahead; less about looking backward,” the department said in an email response to questions. “Our partnership today has evolved far beyond security, to a 360-degree relationship that delivers results for the Iraqi people.”

All of that was enabled by the political changes that the American invasion of Iraq on March 20, 2003, set in motion. Later on, the 2014 takeover of a large swathe of northern Iraq by the Islamic State terrorist group prompted Iraq to turn to Iran as well as the United States for help, cementing Iran’s grip.

As destabilizing as the Iranian involvement has been for many Iraqis, it has been at least as unsettling for much of the rest of the region.

Iraq and Iran are the two largest Middle Eastern countries with a Shiite Muslim majority, and Shiites emerged from the Iraq war empowered across the region — often unnerving their ancient sectarian rivals, the Sunni Muslims, who dominate most other Arab countries.

Under the Iraqi dictatorship, the Sunni minority had formed the base of Mr. Hussein’s power; once he was killed, Iran set up loyal militias inside Iraq. It also went on to dismay Saudi Arabia and the other Gulf monarchies and Israel by supporting proxies and partners, such as the Houthi militia in Yemen, that brought violence right to their doorsteps.

Before 2003, it would have been hard to imagine Saudi Arabia, a pillar of the United States’ Middle East policy for decades and a leading Sunni power, showing open anger toward American leaders over their conduct in the region. But the Saudi king at the time did just that in a January 2006 meeting with the American ambassador to Iraq, telling him that the way Washington saw things going in Baghdad reflected “wishful thinking,” according to a State Department cable released by WikiLeaks in 2010.

By the time of that meeting, Iraqis had approved a new Constitution and held parliamentary elections that swept Shiite parties to power, and Sunni-Shiite sectarian tensions had escalated.

Saudi King Abdullah told the ambassador that before Mr. Hussein’s ouster, his kingdom — Iran’s longtime rival for influence in the Middle East — could count on Iraq as another Sunni power keeping Iran in check.

Now, he said, Iraq had been handed to Iran like “a gift on a golden platter.”

The United States, whose military muscle guided its policies, often with little sensitivity for Iraq’s religious and political dynamics, according to analysts, was not the country best placed to make lasting inroads in Iraq.

Iran, by contrast, could build the bonds created by the Shiite faith it shared with many in Iraq’s population.

Iranian and Iraqi clerics, along with millions of pilgrims, frequented Shiite shrines in both countries each year and enjoyed a mutual understanding of each other’s culture. Tribes and families span their nearly 1,000-mile-long border. And the father of Iran’s 1979 Islamic Revolution, Ayatollah Ruhollah Khomeini, spent 13 years in Iraq’s Shiite pilgrimage city of Najaf, while Iraq’s top Shiite cleric, Grand Ayatollah Ali Sistani, was born in one Iranian holy city and educated in another.

Still, that proximity hardly bred friendship, at least before 2003.

In 1980, when Iraq invaded Iran, the United States and other Western countries quietly supported Iraq in the ensuing war.

The eight-year conflict was so devastating that some analysts say it shaped the mentality of an entire generation of Iranian leaders, making them determined to never again allow Iraq to grow strong enough to attack them. That could explain why, under Mr. Hussein’s repressive rule, which empowered Iraq’s Sunni minority over its Shiite majority, Iran gave shelter and support to both Shiites and Kurds in the Iraqi opposition.

When the United States toppled Mr. Hussein, it neutralized Iran’s foremost enemy without Tehran having to lift a finger. Afterward, the Americans diminished Sunni power in Iraq by dismantling the country’s army and purging the Sunni-dominated governing elite.

Iran saw opportunity.

“What they were looking for and have been looking for isn’t Iranian control,” Ryan Crocker, a former United States ambassador to Iraq, said of Iran. “It’s Iraqi instability.”

After the 2003 invasion, Iranians streamed into Baghdad and Iraq’s Shiite-dominated south: construction engineers to rebuild Iraqi cities, political consultants to train Shiite activists before the Iraqi elections, media professionals to establish Shiite-owned television channels.

Iranian pilgrims who had been barred in the Saddam Hussein era from visiting Iraq’s Shiite shrines now hurried across the border to the Shiite holy cities of Karbala and Najaf, where Iranian companies invested in acres of hotels and restaurants for the millions of worshipers, many of them Iranian, who visit the shrines each year.

A good number of the Iraqi leaders who emerged after 2003 also had ties to Iran. The Shiite and Kurdish opposition politicians who had taken refuge there years before returned to Iraq after the invasion. Some of Iraq’s largest Shiite parties had backing and technical support from Iran, putting politicians from those parties in Iran’s debt when they won seats.

The Americans “somehow didn’t make the connection with Iran explicitly and understand that it’s not the Shiites you are giving the upper hand to, it’s the Shiites backed by Iran,” Marwan Muasher, who was then Jordan’s foreign minister, said last week.

Across Iraq’s southern border, Saudi Arabia and its Gulf allies watched with growing frustration.

Gulf wariness of Iran dated back centuries. Less than 150 miles of Persian Gulf waters separate Iran from the Arabian Peninsula, a dynamic that has long fueled trade rivalries and territorial disputes. After the 1979 Islamic Revolution, the Sunni Gulf monarchies feared that Iran would export its brand of Shiite theocracy across a region traditionally ruled by Sunnis.

Before 2003, the Gulf worried about the Iraqi dictator, too. But Western-led sanctions had weakened Iraq, and the Gulf States and the Iraqis shared a common enemy in Iran.

The toppling of Mr. Hussein unleashed what the Gulf saw as Iran’s destructive power: Now, Iran was increasing its influence over a major Arab country with enormous oil reserves on Saudi Arabia’s northern border, just as evidence was growing that Iran was developing a nuclear program.

These days, no Iraqi prime minister can take office without at least the tacit approval of both the United States and Iran, an arrangement that often produces prime ministers torn between Washington and Tehran. Iraqis with connections to Iran hold posts throughout the government.

The cost of Iranian influence to Iraqi development and stability has been high.

Cut off from the world economy by sanctions, Iran has found an economic lifeline in Iraq, which buys about at least $7 billion in Iranian exports a year while selling only about $250 million of goods in return. The fine print on many medicines shows that they are Iranian made, and large quantities of Iranian construction materials come stacked on truck convoys across the border every day.

Many Iraqi farmers and businesspeople complain that Iran has suffocated Iraqi manufacturing and farming by dumping large quantities of produce and cheap goods in Iraq.

Although Shiites in Iraq’s political elite tolerated Iran’s activities and respected General Suleimani, resentment of Iran among other Iraqis helped set off mass antigovernment demonstrations in 2019 in which protesters demanded an end to Iran’s interference in Iraqi affairs.

Beyond Iraq, Iran has used every conflict in the region to extend its reach.

It inserted fighters into Syria after the 2011 Arab Spring revolt, aiming to prop up Syrian President Bashar al-Assad. It supported the Houthis in Yemen’s civil war against a Saudi-led coalition, establishing Iranian influence on the southern Saudi border. And it further cemented its position in Iraq and Syria by recruiting and training Shiite fighters against the Islamic State.

“Every opportunity that there was in the region, the dominoes fell in Iran’s favor,” said Vali Nasr, a professor of international affairs and Middle East studies at Johns Hopkins University. Exploiting Iraq’s weakness, he added, gradually turned into “a powerful foreign policy tool for Iran on the regional level.”

Particularly worrisome to its Sunni Arab neighbors was Tehran’s consolidation of influence across a so-called Shiite Crescent stretching from Iran through Iraq and into Syria and Lebanon. Some Sunni governments, chief among them Saudi Arabia and the United Arab Emirates, blamed the United States — the country they had long depended on to have their backs — for failing to stop Iran from moving goods, weapons and personnel freely across the region, analysts say.

Later quarrels in the relationship arose over what the Gulf saw as the U.S. failure to intervene in Syria or to protect the Gulf from Iranian-linked attacks on Saudi Arabia and the Emirates.

The State Department said the United States values its relationship with the Gulf and is committed to “to strengthen cooperation, coordination, and consultation with our Gulf partners in all fields, including security, counterterrorism, and economic partnership.”

The Gulf remains deeply connected to the United States, but since the 2003 invasion it has looked to broaden and deepen its ties to China and Russia as alternative partners. When Saudi Arabia agreed to restore diplomatic relations with Iran last week, for example, it did so in Beijing.

That agreement was the latest sign that Saudi Arabia has decided to try engaging with its adversaries rather than holding them at arm’s length as the Gulf monarchies did for years in Iraq.

Despite Iraq and its Gulf neighbors’ shared Arab identity, they all but forfeited the competition for influence to Iran: Whereas Iran was the first to establish an embassy in Baghdad after the United States invasion, a Saudi ambassador to Iraq arrived in Baghdad only last week.

Likewise, the Saudis did not open their deep pockets to Iraq until a few years ago, when they began a tentative effort to invest in infrastructure.

“The only thing we can do is to give the Iraqis another choice that isn’t only Iran,” said Hesham Alghannam, a Saudi political scientist. “We can’t corner them and then blame them for going with the Iranians.”