Iraq’s prime minister, Adel Abdul Mahdi, has announced his resignation, bowing to the country’s top cleric and relentless pressure from protesters demanding the fall of his government and an end to rampant corruption.

It was greeted with both jeers and relief on the country’s unsettled streets, which were this week convulsed by a deadly crackdown by security forces that killed nearly 50 people and edged Iraq closer to a widespread collapse in security.

Abdul Mahdi’s resignation, announced on Friday, is due to be discussed at a parliamentary session on Sunday convened to discuss the crisis. It follows a six-week popular uprising aimed at the heart of Iraq’s establishment, which many across the centre and south of the country say long ago ceased to serve citizens and instead used oil revenues to enrich themselves.

In office for just over a year, the veteran politician had vowed to stay on in the face of a lethal Iranian-backed pushback against the uprising, which has led to almost 400 deaths since it broke out on 1 October. However, an unusually strident demand from Grand Ayatollah Ali al-Sistani that Iraq’s legislature consider Abdul Mahdi’s position appeared to cut further room for manoeuvre.

Sistani, who weighs in on politics only in times of crisis and wields huge influence over public opinion, warned on Friday against an explosion of civil strife and tyranny. He urged government forces to stop killing protesters and told demonstrators to reject all violence.

The intensity of the protests had taken on a revolutionary zeal that the country’s well-armed military was struggling to contain even as it deployed overwhelming force against unarmed demonstrators.

Such has been the momentum of near-daily demonstrations that the very future of post-Saddam Hussein Iraq has been repeatedly placed in question. Until earlier in the week, Iraqi officials believed they had countered calls to topple the leadership and contained the growth of the protests. Up to 200,000 people had taken part in the demonstrations, led by a large disenfranchised working class and joined by some of the middle classes.

But the burning by protesters of the Iranian consulate in Najaf on Wednesday and the deadly crackdown that followed in the southern city of Nassiriya, in which 45 people were killed over the following 48 hours, sparked a new fervour. The governor of Dhi Qar province resigned in response, saying: “It is a dishonour to be part of this system that kills the people of my own country.”

Iraqi demonstrators as flames start consuming Iran’s consulate in Najaf on Wednesday. Photograph: -/AFP/Getty

Karrar Moussawi, a resident of Baghdad, said: “I went out to the protests after 16 years of my people calling out for government reforms and a change in the status quo.

“How is it that we are one of the richest countries and our people are broke? How is it that we still don’t have access to water though we have two major rivers? We have high unemployment, corruption, no services and they still have the guts to fire at us when we protest.”

Baraa Abdel Mutaleb, a professor and feminist rights activist in Najaf, said: “We’re in a maddening dictatorship. We are calling for change. The quality of life and the standard is very poor.

“Despite that, we’re not calling for funds or money to come our way while we’re sitting at home. We’re calling for more than that: the infrastructure is garbage, no electricity, the government is practically nonexistent in practical form. They’re attacking our dignity. From yesterday till today, all these corpses.”

Iraqi security leaders had believed that the attack on the Iranian consulate and advances by demonstrators towards one of Shia Islam’s most important shrines in Karbala had licensed them to take even harsher measures against the protest movement. However, they appeared to underestimate the defiance of communities who, after nearly two months of unrest, had nothing to gain by submitting to force now.

“What happened yesterday was chaotic,” said Ahmad al-Akayshi of Najaf. “The protestors tried to reach the burial area of Abdel Aziz al-Hakim, and they set fire around the area. Security forces began firing at the protesters but they were overwhelmed as the numbers of the protesters grew far more than the forces.”

Mustafa, 37, from Nasiriyah, said: “It was a massacre. They were using heavy machine guns on the protesters. It was like a war. People are only asking for their rights, and they protest, but the government forces treat them as terrorists.

“The government has too much blood of innocent people on their hands; nothing will wash it away after this. Everyone involved in this massacre should be tried publicly. They are firing teargas and smoke grenades at the people, and it has injured hundreds. There isn’t enough to take care of these people.

“Bodies were lying on the ground like in a battlefield. It was a massacre. They didn’t show any mercy to the people who are only marching with a flag in their hands, asking for a better life.”

Additional reporting by Mohammed Rasool