BAGHDAD—Thousands of Iraqis protested the presence of U.S. military in the country, in demonstrations invoked by a prominent Shiite cleric and longtime American foe who has capitalized on anger at the targeted killing of a top Iranian general on their soil.

Moqtada al-Sadr fought American forces after they invaded Iraq nearly two decades ago.

Now,...