ISLAMABAD (AP) — Pakistani Islamists celebrated their victory over the government and called off their sit-in on Monday after the country's law minister resigned, caving in to the fundamentalist protesters who have been demanding his ouster in a three-week-long rally.

After Zahid Hamid's resignation, the Tehreek-i-Labaik Ya Rasool Allah party, which was behind the sit-in in Islamabad and protests in other cities and towns across Pakistan, said they were dispersing peacefully under an agreement with the government.

The development underscored how a small Islamist party was able to pressure the Pakistani government and force it to accept its demands through a protracted standoff that started earlier in November.

The Islamists had demanded Hamid's resignation over an omitted reference to Islam's Prophet Muhammad in a parliamentary bill. He apologized for the omission in the bill, saying it was a clerical error that was later corrected.

But the Islamists persisted, taking to the streets and setting up their sit-in at the Faizabad intersection on the edge of the Pakistani capital. The Islamists effectively blocked the country's key highway, the Grand Trunk Road motorway, linking Islamabad with the eastern Punjab province and the northwest, disrupting life and forcing commuters to look for alternate routes.

Clashes erupted on Saturday when riot police tried to disperse the Islamabad sit-in and descended on the protesters with tear gas and batons, leaving six dead and dozens injured.

The violent crackdown also triggered solidarity protests by Islamists in other Pakistani cities and towns, leading to what could have been a major political crisis that could have paralyzed many urban areas.

Hamid, the law minister, submitted his resignation to Prime Minister Shahid Khaqan Abbasi late on Sunday after security forces held back from another attempt to disperse the protesters, three security officials said, speaking on condition of anonymity as they were not authorized to talk to the media.

Interior Minister Ahsan Iqbal told Justice Shaukat Sadiqui of the Islamabad High Court on Monday that the government signed an agreement with the rally organizers to avoid a "civil-war like situation."

Islamabad-based analyst Imtiaz Gul described the outcome of the standoff as a "retreat" by the state. He said Saturday's crackdown "was a miserably planned and poorly executed."

"This operation was launched by thousands of security forces against Islamists and it ended up with the state's retreat," Gul told The Associated Press.

At the Faizabad intersection, jubilant Islamists kissed the hand of their leader and party chief, firebrand cleric Khadim Hussain Rizvi, handed out sweets and chanted, "God is Great" and "Prophet, we are here for you."

In announcing the deal with the government, Rizvi told supporters they "are immediately ending" the rally. He also thanked the army chief, Gen. Qamar Javed Bajwa, for facilitating the agreement under which Hamid would resign and all detained party activists would be freed.

Rizvi asked his followers to pack up but await the return of their detained activists so they could all go back together to the city of Lahore, the party's base. Buses lined up near the site amid tight security to take them back to Lahore later Monday.

After Rizvi spoke, security forces began removing shipping containers surrounding the sit-in that had meant to prevent the protest from spreading deeper into the city.

Under the deal, the Islamists also agreed not to issue a fatwa, or Muslim edict that could endanger Hamid. The minister's home in eastern Punjab province was twice attacked by Islamists in recent days though he was not there at the time.

The government agreed not to seek any compensation from the organizers for the damage caused to government and public property during Saturday's violence in Islamabad, Rawalpindi and in other parts of the country.

Ghulam Nabi Joya, a middle-aged bearded man from the district of Jhang in Punjab province, was among those celebrating Hamid's resignation at Faizabad.

"This is the greatest news I ever heard in my life. Our efforts in love of the Prophet bore fruit," said.

Shahid Irfan, 22, who was wounded in face and right hand in Saturday's clashes, said he was overjoyed.

"What else we can want from Allah after this," he asked. "I think we are all on a pathway to heaven. ... Prophet, we are here for you."