It is uncertain how Mr. Mahdi plans to enforce the order, or even whether he can. He has set a tight deadline for the militias to comply: July 31.

The decree was welcomed by many of the popular mobilization groups, including some of the largest and most powerful. The Peace Brigades, which are attached to Moktada al-Sadr, the influential Shiite cleric, said they were already putting the new rules in place.

“From today we have dismantled the Peace Brigades and they are now disconnected from Moktada al-Sadr,” said Safa’a al-Tamimi, the brigade’s spokesman. “From now on we will be known as Brigade 313, 314 and 315. We are giving up the name ‘Peace Brigades’ — although we love this name — but we will go with the procedures and we will be under the control of the prime minister.”

Behind the official language, Mr. Mahdi is trying to address a multifaceted problem that has plagued Iraq since the Islamic State began to seize Iraqi territory in 2014. That prompted the formation of informal armed groups to help fight the extremists. Some of those groups were initially fostered, financed and backed by Iran, but they soon multiplied, and many had little or no connection to Tehran.

The United States has become increasingly suspicious about the role of the militias and has designated two of them — Qutab al Hezbollah and Qutab al Nujaba — as foreign terrorist organizations. When Secretary of State Mike Pompeo visited Iraq in June, he raised concerns that some of the Iranian-linked groups posed a threat to American forces in Iraq.