Iran sent the head of the Revolutionary Guard's overseas arm to Baghdad on Wednesday in a bid to block the resignation of the Iraqi prime minister amid widespread anti-government protests in which scores of protesters have been killed.

The visit by Qassem Suleimani, head of the elite Quds Force, came as President Barham Salih announced in a televised speech that Prime Minister Adel Abdul Mahdi was willing to step down if he could do so without causing a "constitutional vacuum".

Mr Suleimani held a secret meeting with Hadi Al Amiri, whose alliance of Iran-backed militias is the second-largest bloc in parliament, to ask him to continue supporting Mr Abdul Mahdi, sources told Reuters.

His visit came after the influential Shiite cleric Moqtada Al Sadr, head of the largest group in parliament, urged Mr Al Amiri to help him remove Mr Abdul Mahdi.

Mr Al Amiri, one of Tehran's key allies in Iraq and the leader of the Badr Organisation militia, issued a statement on Tuesday night agreeing to "work together" with Mr Al Sadr.

But at Wednesday's meeting Mr Al Amiri agreed that the prime minister needed to be given time to enact reforms to calm the streets, a Shiite militia commander told Reuters.

Many of the militia leaders raised fears at the meeting that ousting Mr Abdul Mahdi could weaken the Popular Mobilisation Forces, according to another source familiar with the meeting.

The PMF, also known as Hashed Al Shaabi, is an umbrella of mostly Shiiite paramilitary groups backed by Iran who are influential in Iraq's parliament and have allies in government. They formally report to the prime minister but have their own command structure outside the military.

Following the meeting with Mr Suleimani, Mr Al Amiri informed Mr Al Sadr that getting rid of the prime minister would cause more chaos and threaten stability, a politician close to the cleric said.

In response, Mr Al Sadr issued a statement warning that there would be more bloodshed unless Mr Abdul Mahdi resigned and saying he would not work with Mr Al Amiri again.

"I will never enter into alliances with you after today," he said.

Iraqi Prime Minister Adel Abdul Mahdi, third left, walks to the right of Hadi Al Amri at the funeral ceremony for a slain police commander on October 23, 2019. Reuters

Mr Suleimani, whose Quds Force oversees Tehran-backed militias in Iraq, Syria and Lebanon, is a frequent visitor to Iraq. However, his direct intervention is the latest sign of Iran's increasing influence in Iraq and across the region.

An Iranian security official confirmed Wednesday’s meeting, saying Mr Suleimani was in Baghdad to "give advice".

Iraq's security “is important for us and we have helped them in the past. The head of our Quds Force travels to Iraq and other regional countries regularly, particularly when our allies ask for our help," the official said.

Iraqi security officials told Reuters that Iran-backed militias deployed snipers on Baghdad rooftops to try to help put down an earlier round of protests at the start of October.

If Iraq falls further into crisis, Iran risks losing the influence it has steadily been amassing in the country since the US-led invasion and which it sees as a counter to American influence in the region.

Despite the manoeuvring behind closed doors, Mr Abdul Mahdi's fate remains unclear. He took office a year ago as a compromise candidate between Mr Al Amiri and Mr Al Sadr but faces a wave of protests that has swelled in recent days.

In the 16 years since the fall of Saddam Hussein, a Sunni Muslim, Shiite Iran has emerged as a key power broker in Iraqi politics, with greater influence than the United States in the Shiite-majority country.

But that proxy power battle has rankled ordinary Iraqis who criticise a political elite they say is subservient to one or the other of Baghdad's two allies and pays more attention to those alliances than to Iraqis' basic economic needs.

Despite their country's vast oil wealth, many Iraqis live in poverty or have limited access to clean water, electricity, basic health care and education. Most of the protesters are young people who above all want jobs.

The protests have broken nearly two years of relative stability in Iraq. They have spread from Baghdad across the mainly Shi'ite south and have been met with a security crackdown that has killed more than 250 people.