ISLAMABAD, Pakistan — A Muslim protest movement that paralyzed the capital and convulsed the country for days disbanded peacefully Monday after the government accepted the demonstrators' main demands, including the resignation of the embattled federal law minister.

But the role of Pakistan's powerful military in brokering the agreement raised sharp criticism from Pakistan's judiciary, which accused army officials of an "alarming" reach into politics. Some analysts suggested the army was the real "winner" in the confrontation because it embarrassed the weak civilian government and enhanced the image of the armed forces.

The protesters were enraged over an apparent attempt to change a federal election law in a way that they believed insulted the prophet Muhammad and paved the way for a religious minority group, the Ahmedis, to fully enter the political arena in a country that is 95 percent Muslim.

The protest movement's leader, Khadim Hussain Rizvi, said he would call off its three-week occupation of a highway interchange outside the capital. A botched operation to break up the protesters on Saturday ended in violence and triggered nationwide sympathy protests, with hundreds injured and at least six people killed over two days.

Rizvi also asked protesters across the country to disperse and called for businesses to reopen. Most major cities were shut down for the past two days, with demonstrators flooding the streets and religious rallies held around the clock in scores of towns and communities.

The confrontation was ended after late-night negotiations Sunday. Rizvi publicly praised Pakistan's army chief and his aides for acting as "guarantors" of the agreement, which prevented the situation from possibly spiraling into a national religious uprising.

A long list of demands by Rizvi and his group, the Movement in Service to the Messenger of God, was accepted by the government. The demands included the removal of the law minister, Zahid Hamid, the release of all detained protesters, an official inquiry into Saturday's police assault, and a public accounting of who was behind the attempted law change that provoked the protests.

The agreement signed by Rizvi and top civilian officials specifically thanked Gen. Qamar Javed Bajwa, the army chief of staff, for "saving the nation from a big catastrophe."

But even as a sense of normalcy began to return and traffic flowed in streets that had been blocked by stones and club-wielding demonstrators, the judiciary's criticism of the army's role mostly eclipsed discussion of the religious controversy.

The military is the most powerful institution in Pakistan, and it has often intervened in civilian rule. The current military leadership is believed to dislike the ruling party and its leader, former prime minister Nawaz Sharif. Some Pakistani observers suggested — without offering evidence — that the army orchestrated the religious protests to weaken the party before elections next year.

In a court hearing Monday in Islamabad on the protests, a senior judge demanded: "Who is the army to adopt a mediator's role?" The judge, Shaukat Aziz Siddiqui, said that went "beyond the constitution."

In a ruling, the Islamabad High Court called it "alarming" that a senior army official had signed the agreement with the protesters and "very strange" that the document had acknowledged Bajwa's team as playing the main role in the pact.

Rizvi and his followers objected to new language in the election law that weakened an oath required of all candidates, who must swear they believe that Muhammad was the final prophet in Islam. Officials apologized for the "clerical error" and restored the original oath, but Rizvi's group seized on the issue to rouse the ire of millions of Pakistani Muslims.

The Messenger of God movement is based on reverence for Muhammad and support for Pakistan's strict laws against blasphemy. It claims to be peaceful and has recently fielded candidates for Parliament. But the group also idolized Mumtaz Qadri, a man who assassinated a provincial governor for defending a woman accused of blasphemy.

Some government officials and others have accused Rizvi of using religion for political gain. Interior Minister Ahsan Iqbal further charged that foreign "anti-state" actors who want chaos in Pakistan were behind the protests.

"There was a conspiracy to show that a nuclear state was failing. The agreement was reached to bring the country out of those circumstances," Iqbal told the court hearing. Judge Siddiqui, indirectly chiding both civilian and military leaders, said, "You are destroying the state in your bid to make each other look bad."