WASHINGTON — Over the past four years, American military planning in Iraq has counted on working with Prime Minister Haider al-Abadi, a moderate Shiite Muslim who has managed to rebuild the country’s army, restore sovereignty and partner with both the United States and Iran to defeat the Islamic State.

But the results of the weekend’s national elections in Iraq have torn the American assumptions asunder.

Huge gains in Parliament were made by a party led by the anti-American cleric Moktada al-Sadr, whose implacable opposition to the presence of United States troops in Iraq was a top reason Washington withdrew its combat forces in 2011.

Now, President Trump and the Pentagon must decide whether the United States can move ahead with plans to leave a residual force of about 4,500 American troops in Iraq after the war against the Islamic State.