(CNN) Iraqi Prime Minister Adil Abdul Mahdi has agreed to resign after weeks of anti-government protests that led to hundreds of casualties, Iraq's president announced Thursday.

In a televised speech to the nation on Iraq's Al-Iraqiya TV, President Barham Salih said Abdul Mahdi had agreed to step down on the condition that a successor is agreed to replace him.

"The prime minister has agreed to resign," Salih said, adding that Abdul Mahdi had asked "political blocs to reach an acceptable alternative" in order "to prevent a vacuum."

Iraqi students and professors take part in ongoing anti-government protests in the central city of Diwaniyah on October 31.

One of Iraq's leading Shiite clerics and most powerful politicians, Muqtada al-Sadr, had called on other parties Tuesday to back his push for a no-confidence vote in Abdul Mahdi.

The protests, which have gripped parts of Iraq for the past month, were sparked by longstanding complaints over unemployment, government corruption, and a lack of basic services -- such as electricity and clean water.

Read More