By Gabriel Partos
Central Europe analyst, BBC News
Hungarian Prime Minister Ferenc Gyurcsany has suffered two heavy blows.
Ferenc Gyurcsany needs coalition support to keep his career alive
First, his Socialist Party and its liberal coalition allies, the Free Democrats, were badly beaten in the municipal elections by the centre-right opposition, led by the conservative Fidesz-Hungarian Civic Party.
Fidesz's overwhelming victory more than reversed the Socialist landslide of four years ago, as it has gained control of all but one of Hungary's 19 county councils.
The only qualified success for the governing alliance was in the capital, Budapest, where the popular Free Democrat Mayor, Gabor Demszky, was re-elected for a fifth term.
The counting of the votes had barely started when Hungary's President, Laszlo Solyom, denounced Mr Gyurcsany for using what he called "impermissible means" for securing re-election.
In a television address, President Solyom issued a call, in effect, for the governing coalition - which enjoys a comfortable majority in parliament - to remove their prime minister.
Mr Gyurcsany has responded by calling for a vote of confidence in his government on Friday. He believes he has the continued backing of the Socialists and the Free Democrats who have 210 MPs in the 386-seat parliament.
Meanwhile, Fidesz's leader, Viktor Orban, has raised the political temperature, warning of mass demonstrations unless a so-called constructive vote of no-confidence is called - a procedure which involves putting forward a new prime ministerial candidate to replace Mr Gyurcsany.
Mr Orban, who wants a caretaker government of experts to take charge, may see that procedure as a way of encouraging some of the governing coalition's MPs to abandon their prime minister and oust him by voting with the opposition.
The opposition has vowed to intensify protests if Gyurcsany stays
Prime Minister Gyurcsany has tried to calm nerves within his coalition by attributing the disastrous electoral performance to the tough austerity measures his government has been introducing since June.
He says he is determined to carry on with these reforms to bring down Hungary's budget deficit to 3% of GDP so that Budapest can adopt the euro as its currency.
At a projected 10.1%, the current deficit is the highest in the European Union.
And it was the leaking of Mr Gyurcsany's admission that his government had lied about the parlous state of public finances that unleashed two weeks of protests - including Hungary's worst political violence in 50 years.
But clearly the anger had been fuelled by the belt-tightening measures of recent months.
And the government's disastrous performance in these elections had been foreseen in opinion polls that were taken before the recent protests.
Mr Gyurcsany believes he is the best placed politician to implement the economic reforms required by Hungary's key foreign partners - first and foremost the EU - as well as the business community.
Beyond that, Mr Gyurcsany has little going for him at the moment - other than a realisation among many influential Socialists that without their current prime minister, their party might end up out of power and drifting aimlessly.
But Mr Gyurcsany is now more vulnerable than at any stage in his two-year career as prime minister.
Having taken over when the governing coalition was heading for defeat, he produced a remarkable turn-round, helping his government become the first to win a successive second term in office since the end of communist rule 16 years ago.
Now his coalition is back in trouble, with Mr Orban and Fidesz portraying the municipal election results as a referendum on the government's performance and demanding that the administration be replaced by a caretaker government.
With both the opposition and - more obliquely - the president asking for his resignation, Mr Gyurcsany can only hope that the governing parties will continue their support for him.
That is why the forthcoming vote of confidence is vital for his political survival.
But for now he is facing an uphill task, not least because his goal - putting public finances on a sound footing again - will, at best, take three years to achieve.