BAGHDAD — The Iraqi prime minister ordered the army on Monday to withdraw from Sadr City, the military said, putting the police back in charge of security in a Baghdad neighborhood where dozens of people were killed or wounded at protests over the weekend.

Prime Minister Adel Abdul-Mahdi made the move after a week of violence that gripped Iraq left more than 100 dead and thousands wounded.

The unrest is the most serious challenge facing Iraq, two years after a victory against Islamic State militants. The chaos also comes at a critical time for the government, which has been caught in the middle of increasing tensions between the United States and Iran. Iraq is allied with both countries and hosts thousands of American troops, as well as powerful paramilitary forces allied with Iran.

Monday’s order appears aimed at calming tensions in Sadr City, a sprawling and heavily populated Shiite neighborhood where the populist cleric Moktada al-Sadr enjoys wide support.