Prachanda has only served as PM since elections in 2008
The Maoist Prime Minister of Nepal, Pushpa Kamal Dahal, has dramatically announced his resignation in a television address to the nation.
"I have resigned from the post of prime minister," Mr Dahal - who is best known as Prachanda - said in his address.
The move follows his efforts - opposed by the president - to sack the army chief, who has refused to integrate ex-Maoist rebel fighters into the force.
The president said Gen Rookmangud Katawal's sacking was unconstitutional.
Correspondents say Prachanda's resignation has pushed Nepal into a fresh political crisis following an election win by the Maoists last year.
In his TV address, Prachanda said he was stepping down "for the protection of democracy and peace" in Nepal.
"The move by the president is an attack on this infant democracy and the peace process."
"The interim constitution does not give any right to the president to act as a parallel power," he said.
Prachanda accused President Ram Baran Yadav of taking an "unconstitutional and undemocratic decision" by overturning his efforts to get rid of Gen Katawal.
His resignation - which is almost certain to be accepted by the president - follows months of worsening tensions between the ex-rebels and their former foes in the military.
Correspondents say that the expectation now is that the Maoists will sit in opposition in parliament. There is no suggestion that the Maoists will abandon constitutional politics, they add, but there are fears that the political crisis could threaten the peace agreement signed in 2006.
The Maoists want their fighters, who are currently restricted to United Nations-supervised camps, to be integrated into the regular Nepali army.
But the army has refused to take on the fighters, who number about 19,000 hardened guerrillas, arguing that they are politically indoctrinated.
Correspondents say that the crisis is the most serious in Nepal since its 10-year long civil war between the army and the Maoists came to an end.
The peace agreement allowed the rebels to enter the political mainstream. Last year they won elections, but not convincingly enough to hold on to power without the support of other parties.
Two parties which acted as key members of the coalition withdrew from the government on Sunday in protest against the dismissal of Gen Katawal.
That left the Maoists with a wafer-thin majority and the prospect of needing to win a confidence vote to remain in government.
Gen Katawal is nearing the end of his career
The latest developments came to a head when President Yadav ordered the head of the army to remain in office despite his dismissal by Prachanda.
"Being the head of the state and the supreme commander of the Nepal Army I order you to continue with your duty," the president told Gen Katawal by letter.
The BBC's Nepali editor in Kathmandu, Rabindra Mishra, says that the country now faces a major crisis which could result in the peace process unravelling, the new constitution remaining unwritten and the Maoists struggling to stay in power.
Our correspondent says that the situation at the moment is fluid, with no-one able to say whether a compromise can be reached between feuding factions.
The Maoists fought Nepal's army for more than a decade before giving up their armed revolt, and the relationship between the two sides has been tense since the former rebels came into power.
Some 13,000 people died during the conflict.
In March, the Nepalese Supreme Court ordered the defence ministry to put on hold its decision to retire eight generals from the army.
Several coalition representatives walked out of the cabinet meeting in protest at the proposed sacking, but a vote went ahead.
"We have been insisting that the decision on the army chief should be taken through consensus among all political parties but the prime minister decided to ignore us," said Deputy Prime Minister Bamdev Gautam, according to the Associated Press news agency.
Gen Katawal is due to retire in four months.