When Iraq’s prime minister traveled to Washington in the spring, he hoped to negotiate a much-needed economic development package and discuss shared strategic interests with the United States, one of his country’s most important international allies.

But the very day he arrived in mid-April, events unfolding at home served as a stark reminder of the competing influences that the Iraqi prime minister, Mohammed Shia al-Sudani, is caught between: Iran was sending drones and missiles to attack Israel and at least one Iraqi militia backed by Tehran participated in the attack.

Both the United States and Iran have long held sway in Iraq. But since the war between the U.S. ally Israel and the Iran-backed Hamas broke out in Gaza almost 10 months ago, they are increasingly at odds.

With regards to Iraq, one of the most contentious issues is the continued presence of 2,500 American troops on Iraqi soil. Over the past 20 months, Iran has used its considerable influence to try to persuade the Iraqis to push those forces out, and if it succeeds, it would give Tehran even more say over Iraqi policies.

Last week, in the latest round of discussions in Washington on a reconfiguration of the military relationship, Iraq called for a drawdown of the U.S.-led multinational force within about a year, underscoring its determination to thin out the American presence.

Iran’s clout in Iraq has grown in the past few years as Iraqi Shiite political factions close to Tehran have come to dominate the national government. At the same time, the Iraqi militias that Iran has cultivated over the past 20 years have come to form a growing part of the national security forces since they were folded in a few years ago.