Iraq gets security and economic support from the United States for the long-term effort to defeat ISIS, while Iran also provides security support and is aligned with Iraq's majority Shiite population.
But this time the stakes are higher for Iraq as the U.S. accuses Iran of engaging in a "campaign" across the Middle East to threaten U.S. forces and partner nations, the main reason why the Pentagon dispatched an aircraft carrier and other forces to deter attacks that could be carried out by Iran or Iranian-backed groups.
U.S. officials are concerned that Iran has given the green light to Iranian-backed militias in Iraq to attack the more than 5,200 U.S. forces helping Iraqi Security Forces. And reflecting the unique situation in Iraq, some of those security forces are Iranian-backed militias that fall under the control of the Iraqi government.
The U.S. believes that Iran or Iranian-backed groups were behind an unsuccessful May 19 rocket attack fired at the Green Zone in Baghdad that targeted the U.S. embassy.
Amid concerns U.S. forces also could be targeted inside Iraq, Iraqi Prime Minister Adel Abdul-Mahdi said on Tuesday that Iraq would not tolerate having its territory become the scene of direct or indirect combat between the two nations.
In late May, Iraq's foreign minister offered to help serve as a mediator between Iran and the United States. That offer was a natural progression from the balancing act that Iraq has maintained between two sides which are almost always at odds with each other.
"I actually think Iraq is pretty good at playing this game," said Michael O'Hanlon, with the Brookings Institution.
O'Hanlon said Iraq could continue that balancing act as long as Iran does not gain overall influence with the Iraqi government.
"To the extent that the Iraqis are able to maintain some degree of separation, and we are able to maintain that balance, through our military presence and our economic aid, I think the Iraqis are pretty good at that," he said.
O'Hanlon said that Iraq's last two prime ministers wanted "the balance relationship with both countries and that's good enough for us, given our core interests there."
Last Friday, Secretary of State Mike Pompeo phoned al-Mahdi to make the case that Iran was responsible for last week's attacks on two oil tankers in the Gulf of Oman.
According to a State Department readout of Pompeo's call, the secretary of state "appreciated Prime Minister al-Mahdi's commitment to protect U.S. personnel in Iraq supporting the Iraqi people and continuing the defeat ISIS campaign, and his continued efforts to counter threats to Iraq's sovereignty from Iran-backed militias. The United States will continue to help Iraq build out its security forces."
The statement made clear that while deterring Iranian attacks is the key focus right now, the United States wants to maintain the key strategic effort of working with Iraq to defeat Islamic State militants inside that country.
"This relationship is among our most compelling strategic interests," Michael Mulroy, deputy assistant secretary of defense for the Middle East, said in a statement provided to ABC News.
While defeated militarily inside Iraq, the Iraqi government continues fighting insurgent fighters -- remnants of ISIS -- in its territory. And it will continue to rely on American and coalition support with its long-term goal to fully eliminate the Islamic State.
Ensuring a final defeat of ISIS is "vital U.S. national security interests," he added.
The 5,200 U.S. military personnel, as well as others from 15 other members of the anti-ISIS coalition, remain in Iraq to support the fight.
According to Mulroy, the U.S. currently helps train and equip 28 Iraqi brigades to maintain their readiness.
"The priority is to empower Iraq's professional and capable security forces to protect its sovereignty and to prevent an ISIS resurgence," Mulroy said. "The more capable Iraq's security institutions, the more resilient Iraq will be in the face of its enemies."