This post has been updated.

Tensions between the United States and Iran have escalated dramatically over the past week, culminating in a stunning airstrike that killed a revered Iranian military leader in Iraq just days after supporters of a pro-Iranian militia attempted to storm the U.S. Embassy in Baghdad.

The location of this round of violence shows how Iraq is again stuck in the middle of the dispute between the United States and Iran — a dangerous place to be for a country still reeling from years of dictatorship, war and extremism.

A rocket attack in late December on a base housing U.S. troops in the northern Iraqi city of Kirkuk killed an American contractor. The United States blamed an Iranian-backed group for the attack and in response launched airstrikes against bases along the border with Syria used by the Kataib Hezbollah militia, killing 25 of its fighters and injuring more than 50.

The airstrikes drew condemnation from not only Tehran but also Baghdad, which declared they were a violation of Iraqi sovereignty. A crowd of hundreds, many armed, broke into a reception area of the U.S. Embassy in Baghdad on Tuesday, shouting, “Death to America.”

The Pentagon announced late Thursday that the United States had killed Iranian Quds Force commander Qasem Soleimani and another senior Iranian-linked figure in an airstrike early Friday local time near the Baghdad airport, claiming that the legendary tactician was planning more attacks on U.S. diplomats and officials in the region.

Why are the United States and Iran at odds?

Iran was a close ally of the United States during most of the reign of Shah Mohammad Reza Pahlavi. But the shah was overthrown by the 1979 Iranian revolution and replaced with a Shiite-led Islamic Republic. That November, Iranian militants took about 70 Americans hostage at the U.S. Embassy in Tehran. Many of the hostages were held for 444 days. Iran’s relationship with the United States rapidly deteriorated and has remained strained since.

Some point to U.S. meddling in the Middle East and its alliance with Israel and rival Sunni powers as justification for Iranian suspicions, while others argue that Iran is an expansionist power, eager to push the influence of the Shiite branch of Islam across the Middle East. Washington and its allies in the Middle East also suspect that Iran is seeking to develop a nuclear weapons program.

Both sides have intermittently tried to lower tensions, emphasizing that their issues are with the respective governments and not the people of the nation. Protracted negotiations resulted in a 2015 deal between Iran and a number of world powers, including the United States, that sought to place restrictions on Iran’s nuclear program.

Under President Trump, United States-Iranian relations have taken a decisive turn for the worse. Here's a brief history of the tumultuous relationship. (Joyce Lee/The Washington Post)

Why are both the United States and Iran interested in Iraq?

Iraq is Iran’s neighbor. The two nations share a 900-mile-long border. Historically, Iraq had formed part of Persia for hundreds of years. Roughly 70 percent of its population is Shiite, with most of the remaining population Sunni (in Iran, more than 90 percent of the population is Shiite), though Iran has almost four times the territory as Iraq.

In the modern era, the two countries have had a tense relationship: Iraqi dictator Saddam Hussein invaded Iran in 1980, prompting an eight-year war that left hundreds of thousands dead. However, after Hussein’s Sunni-dominated government was toppled by the U.S.-led invasion of Iraq in 2003, Iraq came to be dominated by Shiite political groups, some of which were allied with Iran.

The United States was opposed to Hussein’s Baathist government but provided support for Iraq during its war with Iran. Later, after Iraq invaded U.S. ally Kuwait in 1990, the coalition defeated Hussein’s forces in the Persian Gulf War. President George W. Bush labeled both Iraq and Iran part of the “axis of evil” in a 2002 speech, despite their opposition to each other.

The invasion of Iraq in 2003 ousted Hussein, but U.S. troops remained in the country to combat a violent insurgency. Although the administration of President Barack Obama completed the withdrawal of troops in 2011, troops were redeployed to the country in 2014 to combat the Islamic State, an extremist Sunni group.

What effect did the rise of the Islamic State in Syria and Iraq have on the U.S.-Iran relationship?

The Islamic State has its origins in Iraq, but it came to prominence in the chaos of the war in neighboring Syria that began in 2013 and is ongoing. At its peak in late 2014, the self-proclaimed caliphate controlled an area the size of Britain and used it as a base to call for attacks, including on both U.S. and Iranian interests.

Iran and the United States backed opposing sides in the Syrian war. Tehran viewed Syrian President Bashar al-Assad as a key ally in the region, whereas the United States and other Western powers backed rebels who opposed his government. But for both, the Islamic State presented a more pressing problem.

With U.S. airstrikes, as well as the intervention of forces loyal to Iran and the Russian military, the Islamic State ceded the last of its territory in March. However, the end of that fight raised the possibility of new conflict between Iran and the United States. President Trump has taken a critical view of Iran since taking office in 2017.

The tension between the United States and Iran was especially noteworthy in Iraq, where about 5,000 U.S. troops are deployed ostensibly to aid the Iraqi fight against the Islamic State. Powerful Shiite militias, many allied with Iran, expanded their reach during the battle to liberate land held by the Islamic State as part of the Popular Mobilization Forces, a state-sponsored organization of militias.

What relationship does Iran have with groups in Iraq and Syria?

Iran has long been accused of running a network of proxies across the Middle East, using Shiite militias and political parties to undermine rival governments. Often, the exact nature of its relationship with these groups, and the level of autonomy from Tehran, is hard to gauge for outsiders, which critics say gives Iran a degree of plausible deniability for anti-U.S. actions.

As leader of the Islamic Revolutionary Guard Corps’ elite Quds Force, Soleimani was personally responsible for these clandestine international operations and gained international notoriety as an influential but shadowy figure.

In Iraq, there are a variety of Shiite militias. Not all formed at the same time, and they do not have identical interests, but they have had increasing political clout since the battle against the Islamic State, gaining almost a third of the seats in Iraq’s parliament in 2018 elections.

Over the past year, frequent rocket attacks on bases used by U.S. troops in Iraq have led to increasing tension. After the strikes against Kataib Hezbollah on Sunday, a senior U.S. State Department official briefed reporters that the blame lay not just with Iran but also with Iraq. “It is their responsibility to protect us, and they have not taken appropriate steps to do so,” the official said.

The apparent ease with which supporters of Kataib Hezbollah and other Shiite militias were able to reach the U.S. Embassy, which lies in Baghdad’s secure Green Zone, surprised many observers. Trump tweeted Tuesday that he expected Iraq to protect the embassy.

How has Trump changed the United States’ relationship with Iran and Iraq since entering office?

Trump viewed the Obama-era nuclear deal with Iran with suspicion and argued that the previous administration had not done enough to curtail Iranian influence across the region. The president pulled the United States out of the deal in May 2018 and reimposed sanctions on Iran.

The United States has since specifically targeted Iran’s supreme leader, Ayatollah Ali Khamenei, a religious and political figure who is the ultimate decision-maker in the country. It has also designated the Revolutionary Guard as a terrorist organization.

Despite the political and economic pressure on Iran, there has been no indication that support for foreign militias has been curtailed. Iran has been linked to attacks on a Saudi oil facility, as well as foreign tankers in the Persian Gulf. Though most parties to the nuclear deal remain in the agreement, Iran has also started enriching and stockpiling uranium at a higher level than allowed by the deal.

At the same time, tensions between the United States and Iraq have escalated under Trump. In early 2019, Iraqi President Barham Salih said his country would reject Trump’s idea that the United States could keep American troops in Iraq to “watch” Iran. The Iraqi government argued that Sunday’s airstrikes were an affront to their nation’s sovereignty and broke the status-of-forces agreement that allows U.S. troops in Iraq.

Some analysts argued that the targeting of Soleimani in Iraq, as well as Abu Mahdi al-Muhandis, an Iraqi militia commander, would incite the Shiite militias who revered the Iranian.

But Iran’s influence in Iraq is also a point of contention: As thousands took to the streets to protest the government this fall, some targeted Iranian interests, even burning down the Iranian Consulate in Karbala in early November. For many Iraqis, Soleimani’s death will be something to celebrate.