ISLAMABAD — Pakistani officials struck a deal late Thursday with a fiery Muslim cleric to end four days of anti-government protests by thousands of people that largely paralyzed the capital and put intense pressure on the government.

The cleric, Tahir-ul-Qadri, galvanized many Pakistanis with his message alleging that the nation’s politicians are corrupt thieves who care more about lining their pockets than dealing with the country’s pressing problems, such as electricity shortages, high unemployment and deadly attacks by Islamic militants.

But his demand that the government be dissolved and replaced by a military-backed caretaker administration raised concerns that he was being used by the nation’s powerful army to try to delay parliamentary elections expected this spring. The army has a history of toppling civilian governments in military coups and has done little to hide its disdain for the country’s politicians.

Qadri has denied the allegations. He also demanded electoral reform to prevent corrupt politicians from standing for elections.

The agreement was reached after hours of negotiation inside a bulletproof container the religious leader was using at the demonstration site. Thousands of protesters packed into the main avenue running through the capital, Islamabad, danced and cheered when Qadri announced from the container that he had hammered out an agreement with the government.

The government agreed with the cleric to dissolve the National Assembly before its term ends in mid-March, giving 90 days until elections are held, according to a member of the negotiating team. That would give time to make sure politicians are eligible to stand for election, he said. The government also agreed that the caretaker administration, which normally precedes elections, would be chosen in consultation with all parties, the negotiator said.

A declaration laying out the agreement between the government and Qadri was signed by Prime Minister Raja Pervaiz Ashraf as well as the high-level government officials who made up the negotiating team, an official in the premier’s office said.

Both officials spoke on condition of anonymity because they were not authorized to talk to the media.