President Trump threatened Iraq with sanctions and a bill for billions of dollars if the U.S. is forced to withdraw its troops from the nation after the Iraqi parliament, responding to a U.S. airstrike that killed a powerful Iranian general on its soil, voted in favor of expelling American forces.

The nonbinding resolution—passed Sunday with the backing of Shiite politicians—urges Prime Minister Adel Abdul-Mahdi to rescind Iraq’s invitation to U.S. forces that helped rescue the country after Islamic State overran about one...