Nepal's Maoist prime minister has resigned, leaving a leadership vacuum just weeks before the second round of local elections.

Pushpa Kamal Dahal took office only nine months ago. The municipal and village assembly vote is the first in the past two decades.

His exit from government on Wednesday was somewhat expected under a power-sharing deal with the Nepali Congress Party.

It came earlier than predicted though after the Communist UML opposition party threatened to block Dahal's speech in parliament, saying the government had created local and municipal bodies without due legal process.

Dahal's final month in office was marked by a clash between his government and the chief of the Supreme Court over the appointment of a new police chief.

"I have decided to fulfil the commitment made to the Nepali Congress when I became prime minister," he said, reading from a statement.

"I am going to the president to tender my resignation right now."

It was not Dahal's first resignation. In 2008, he quit as head of government in protest when the president reinstated the army chief Dahal had fired.

Local elections

A new government, which would be Nepal's 25th in the past 27 years, will be responsible for completing the remaining phase of the local polls - a precursor to national elections due to be held by the end of the year.

Sher Bahadur Deuba, 70, the head of the Nepali Congress Party, is due to replace Dahal, who will stay on as caretaker prime minister until a new leader is picked.

The two parties agreed to switch prime ministers after nine months, after which Deuba would become Nepal's leader.

READ MORE: Nepal - Waiting for the 'disappeared'

However, the formal choice of a new leader could take several days as politicians are required to take a week to agree on a consensus candidate before legislators are asked to elect a successor in a parliament where no party commands an absolute majority.

If the power-sharing deal is to be respected, the two parties do have enough votes in parliament to obtain the simple majority vote needed to form a new coalition government.

Nepal is recovering from devastating earthquakes two years ago in which 9,000 people were killed.