Madagascars prime minister announced his resignation on Monday in the first step towards the naming of a "consensus" premier to resolve a political crisis sparked by controversial electoral reforms.

The African island nation has been rocked by violent protests that initially sought to oppose the new laws the opposition said were crafted to bar their candidates from participating in elections planned for later this year.

The Constitutional Court has ordered President Hery Rajaonarimampianina to form a government of national unity with a "consensus prime minister" to avert a full-blown crisis.

For that to happen, the current government was required to resign and the president was ordered to name a new prime minister by June 12.

"I will tender my resignation to the president today. As a statesman, I cannot be an obstacle to the life of the nation," Olivier Mahafaly Solonandrasana told a press briefing.

"I resign willingly and with happiness. I have no regrets today and I can leave with my head held high."

"I will leave this magnificent palace, (but) I tell you this is not 'goodbye'," he added without giving details of his future plans.

No successor to Solonandrasana has yet been named.

'We have compromised'

Since April 21, hundreds of opposition supporters have occupied the capital Antananarivo's May 13 square, initially to protest the president's proposed electoral reform package.

But after those proposals were overturned by the courts, the protests became a full-blown movement to oust Rajaonarimampianina.

The Constitutional Court ruled that the composition of the new unity government should proportionately reflect the outcome of the last legislative elections in 2013.

However, the ruling triggered fierce debate between the government and the opposition over its interpretation.

Both sides say they hold the majority in parliament, where many legislators have switched allegiances since 2013.

"We are in the process of implementing the political deal. Without the resignation of our prime minister, the president wouldn't be able to name a new one," said Rivo Rakotovao, the head of the ruling HVM party and senate leader.

Over the weekend, Rajaonarimampianina rejected three opposition nominations for the job of "unity" prime minister. All of the opposition nominees are members of the Mapar party which is led by former president Andry Rajoelina.

"We have compromised. I reiterate my (weekend) call for a prime minister who is not from their side or ours," added Rakotovao.

Neither domestic nor international efforts to resolve the crisis in the former French colony have yet borne fruit.

The most recent effort, a gathering of the National Reconciliation Council that included government and opposition delegates, finished inconclusively on Friday.

Defence Minister Beni Xavier Rasolofonirina threatened on Thursday to deploy security forces if political efforts to resolve the crisis fail.

"The resignation is logical in terms of the current crisis. Now they should name a new PM from among the 73 (opposition) lawmakers," said Mapar parliamentarian Jean-Brunel Razafitsiandraofa.