Perhaps no other country faces a greater exposure to competition between Iran and the United States than Iraq. So far, inside Iraq, the Trump administration has sensibly prioritized counterterrorism partnership against ISIL over its broader policy of competition with Iran. But a pair of recent developments may test that approach.

First, President Donald Trump has taken an increasingly belligerent stance toward Iran. He pulled out of the Joint Comprehensive Plan of Action. He seeks to cripple Iran’s economy and signaled a willingness to confront Tehran across the Middle East. As U.S. focus shifts from anti-ISIL to countering Iran, and America’s Gulf and Israeli partners strike at Iranian forces in Syria and Iranian-backed Houthis in Yemen, Iraqis and others are wondering whether Washington will begin to treat Iraq as another front in their region-wide anti-Iranian pressure campaign. But forcing Iraqis to choose between their partners, as they compete elsewhere, would likely backfire and play into Iran’s hands.

Second, anti-American coalitions outperformed the Victory alliance led by Iraq’s technocratic prime minister, Haider al-Abadi, in last week’s elections. Rather than wade into the complex realities of Iraqi politics, the Trump administration might be tempted to declare mission accomplished against ISIL, pack up and go home. But this too would play into Iran’s hands.

Between these bad options — confronting Iran inside Iraq and walking away — lies a third: the long game. It requires accepting that Iraq will continue to uncomfortably straddle America and Iran. Since the 2003 invasion, American policy has whiplashed between surging troops in and pulling troops out. It is time to construct a more durable bilateral relationship that sees Iraq as a partner, rather than a client. That demands constructive engagement in support of Iraq’s fragile but stabilizing sovereignty. It entails support for compromise and pragmatism during Iraq’s difficult government formation process and promotion of Iraq’s continued regional integration. It means defining a sustainable, more restrained security cooperation paradigm in the wake of the defeat of ISIL. Such an approach is more carrot than stick. But it will also require articulation of viable redlines, for example if U.S.-supplied advanced weaponry leaks to militias or sectarianism once again goes off the rails. A more confident, more stable Iraq will be more resilient against both home-grown Sunni extremism and Iranian interference, and could yet play a productive role in a region riven with conflict.

***

Media coverage is understandably focused on the performance of two Shia-led blocs critical of the United States. But the government formation process is just beginning, and it promises to be contentious and lengthy. Scratch beneath the surface and Iraqi politics is far more dynamic than the easy veneer of a country divided neatly, like Caesar’s Gaul, into three parts: Shia, Sunni, and Kurds. Abadi’s coalition performed better in Sunni-majority Mosul than among his traditional Shia base in Baghdad. Iraq’s intra-Shia political rivalries can be as contentious as its sectarian ones. There may well be surprises ahead.

The leader of the top vote-getting list, Shia populist Moqtada al-Sadr, is no friend of America and has fought its troops in the past, but neither is he a friend of Iran. He ran as an Iraqi nationalist, condemned Iranian influence, and warned against gangsterism. Sadr, who seems to aspire to be a kingmaker rather than the prime minister, has shown a willingness in recent years to work across ideological and sectarian lines. No issues have been as important to the Iraqi public — and perhaps the election results — as Sadr’s core issues of anti-corruption and basic service provision.

Meanwhile, Trump’s decision to pull out of the Iran nuclear deal puts the United States on a collision course with Tehran across the Middle East. Iran, too, might decide intensify its own competition inside Iraq in the face of U.S.-led regional pressure. But prioritizing a zero-sum anti-Iranian framework within Iraq is unlikely to benefit either Iraqis or Americans. Iraqis worry, as one politician warned one us of in Baghdad after Trump’s hawkish anti-Iran speech last fall, “when the elephants fight, the grass gets trampled.” It is easy to imagine Trump offering the new government an impossible “my way or the highway” choice or becoming disinterested amid myriad domestic and international crises.

Iran’s regional gains have tended to come where Shia populations combine with acute institutional grievances. Since Saddam’s removal in 2003, Iranian influence has ebbed and flowed in roughly inverse proportion to the level of stability. It surged during the horrific sectarian violence between 2005 and 2007, and again after the fall of Mosul in June 2014, when the Iraqi government, fearful that Baghdad might be overrun, mobilized Iranian-backed militias and young Iraqi volunteers to form what became the officially-sanctioned Popular Mobilization Forces. But it ebbed again in both cases after a degree of stability returned, most recently after Abadi began to look to the United States as its primary military partner against ISIL.

Today, ISIL has lost its caliphate, and life across Iraq has begun to normalize. Iraq enjoys a level of democratic competition absent elsewhere in the Arab world except in Tunisia. Four parliamentary elections since 2005 have resulted in multiple turnovers of government. Outsized Iranian influence inside Iraq remains problematic for a host of reasons. But Iraqi nationalism has emerged as an important and credible counterweight, from religious clerics in Najaf who reject Iranian-style fundamentalism to Shia politicians in Baghdad who chafe at Tehran’s dictates.

So how should Washington more productively navigate this difficult policy terrain?

First, the Trump administration needs to show up to engage with Iraq’s political leaders as they form the new government. The days of American tutelage, when U.S. interventions could be decisive in government formation, in Baghdad are long gone, with decidedly mixed results. Washington should resist the urge to pick winners or dictate outcomes. But refraining from direct interference does not mean idly standing by. Qassem Soleimani, the Iranian Quds Force commander, has already begun high-handedly holding audiences with Iraqi politicians in Baghdad. The most effective American response may be to highlight and reject this brazen interference and clientelism and offer a more constructive alternative. Washington should remain engaged with Iraqis supporting political compromise and pluralism. This includes working with deeply divided Kurdish leaders to form a united front in favor of moderate leadership in Baghdad so they cannot be coopted individually by Shia hardliners with offers of the keys to the Iraqi presidency. The United States has interests it should make clear to Iraqis. These include maintaining counterterrorism partnership, promoting an inclusive leadership, stabilizing liberated areas, and supporting Iraqi sovereignty from various threats, any coming from the direction of Iran. America should also make clear that the scope for future cooperation will depend on the extent to which the next Iraqi government fulfills those goals.

America can play a respectful but influential role. But this requires Washington to back its diplomatic representatives in the field with a level of consistent, coherent support that has been largely absent over the past year. Amid the unprecedented turnover of White House and cabinet officials, the Trump administration has not designated a senior official to manage its Iraq policy as the last administration did in the form of Vice President Joe Biden.

Second, the best way to fight Iranian influence in Iraq is by promoting Iraq’s independence, reflecting Iraqis’ own preferences. The growing sense of Iraqi nationalism, at least outside the Kurdish areas, creates diplomatic opportunities. The United States should continue to support Iraq’s development of relations with its Arab neighbors, particularly Saudi Arabia. This is a promising shift for which the Trump team deserves credit. But it is one that needs sustained U.S. support if it is to be translated into tangible results. If these efforts succeed, Iraq might accelerate its evolution from a subject of regional competition to a more productive regional actor in its own right.

Third, the United States needs to articulate and pursue a more sustainable security cooperation paradigm with the new government in Baghdad. As Iraq consolidates its battlefield gains against ISIL, the role of American troops is already diminishing. The next Iraqi government could demand the full withdrawal of American troops. But as campaign rhetoric subsides, the next Iraqi government may well prove itself eager to counterbalance Iranian domination, willing to respect U.S. concerns, and interested in an ongoing security partnership with the United States. Over time, this could create an opening to work with Baghdad to incorporate the militias mobilized to fight ISIL into its regular military or disband them.

Memories of occupation linger in the popular imagination. To be sustainable, any follow-on American military presence must be discreet and limited in scope and numbers. This presence needs to both respect Iraqi sovereignty and provide legal protections for American forces to remain in advisory roles. It also needs to reflect Iraqi priorities, as well as American ones. This will require patience, persistence, and flexibility, but offers the prospect of significant security and political benefits to America and Iraq alike.

***

There will be moments of opportunity and necessity to work with Iraqis to constrain and even push back against Iranian overreach into Iraq. But the slow normalization of Iraqi politics will ultimately do far more to support bilateral relations than a foolhardy “with us or against us” lurch. After 15 years of being either all in or all out, now is the time for Washington to seek a more sustainable medium.

The good news is that a modest American investment in Iraq can go a long way. Iraq’s politics can be dizzying and dysfunctional, but they break the authoritarian mold. Iraq remains on the frontlines of three key fights: the fight against ISIL and its successors, the fight against Iranian regional expansionism, and the fight for the notion that peaceful and even democratic coexistence is still possible in the heart of the Middle East. America has a stake in all three.

Iraq is developing its own distinct politics, which at times will prove mystifying and complicated. Publics everywhere are defying their elites, and Iraq seems to be no exception. For Iraq’s long-term development, that may not be a bad thing. What matters most is what happens next. After an extraordinarily difficult 15-year period, Washington should stick around to find out.

Perry Cammack (@perrycammack) is a fellow at the Carnegie Endowment for International Peace and a former member of the Policy Planning Staff at the U.S. Department of State. Prior to that, he worked for nearly ten years on the Senate Foreign Relations Committee for then Senators Joe Biden and John Kerry.

Daniel Benaim (@danielbenaim) is a Senior Fellow at the Center for American Progress and a Visiting Assistant Professor at New York University’s Program on International Relations. He previously served as a Middle East advisor and foreign policy speechwriter to Vice President Joe Biden, Secretary of State Hillary Clinton, and then-Senate Foreign Relations Committee Chairman John Kerry.

Image: David Stanley/Flickr