Italy's 87-year-old President Giorgio Napolitano was re-elected by lawmakers on Saturday to end a deadlock on forming a new government, with cheers in parliament but jeers at a rally outside by a protest party that denounced a "coup d'etat".
The ex-communist Napolitano won with a sweeping majority of 738 ballots out of 1,007 possible votes -- far ahead of the 217 received by leftist academic Stefano Rodota whose candidacy was put forward by the anti-establishment Five Star Movement.
"We must all bear in mind, as I have tried to do, the difficult situation of the country," Napolitano said at a brief ceremony in the presidential palace where he was handed the official results of the election.
He called on bickering politicians to "honour their commitments" and said the presidential election process had been "tormented" and taking place at "a critical time" for the country.
Meanwhile hundreds of people rallied in Rome at a tense protest called by Five Star Movement leader Beppe Grillo, a former comedian turned firebrand who was expected to arrive later on Saturday.
"Jokers!" "Thieves!" "Shame!", they shouted.
Grillo, whose party came third in February elections shaking up the traditional political system, called for a "popular mobilisation".
The election brings to an end a chaotic series of votes this week that saw the candidacies of former European Commission president Romano Prodi and former trade union leader Franco Marini rejected and the centre-left tipped into complete disarray.
The president on Saturday agreed to stand for an unprecedented second term -- the first Italian president to do so -- after pleas from outgoing prime minister Mario Monti, rightist leader Silvio Berlusconi and leftist leader Pier Luigi Bersani.
Monti said in a statement he had called Napolitano to thank him for his "spirit of sacrifice" during "a difficult phase of our nation's life".
Napolitano even received the backing of the Vatican's official newspaper, the Osservatore Romano, which called him a "true resource".
He will be officially sworn in on Monday in the lower house of parliament at 1500 GMT and begin sensitive talks to set up a new government.
Napolitano is considered as being above the party political fray and is respected by rival forces, which have been at loggerheads since a general election that yielded no clear winner and left the eurozone's third largest economy in limbo.
Monti's cabinet has limped on with only interim powers since the elections and the reform programme he began has been at a standstill.
European Commission President Jose Manuel Barroso congratulated Napolitano on his re-election saying in a statement that he would provide "a decisive contribution to our common European ideal".
Napolitano as recently as last week had ruled out the prospect of staying on, saying he had "done everything I could" to end the stalemate and saying he was looking forward to his retirement as his seven-year mandate draws to a close.
He is not expected to serve out the full term but instead only stay in office the time needed to end the deadlock and then resign at the end of a political career that began in the Second World War when he was an anti-fascist activist.
A former top Italian Communist Party official, Napolitano was credited with engineering former European commissioner Monti's rise to power after then premier Berlusconi's chaotic ouster in 2011 during a wave of panic on the financial markets.
Italian presidents hold a mostly ceremonial role that takes on huge importance during times of instability and can help form governments.
The main centre-left coalition narrowly won elections in February but failed to get enough votes for an overall majority in parliament.
The leadership of the leftist Democratic Party (PD) -- its secretary Bersani and chairwoman Rosy Bindi -- resigned on Friday after the two presidential candidacies it proposed fell through due to a rebellion from within its own ranks.
"Collective Suicide", read the headline of an editorial in the leftist daily Il Fatto Quotidiano, adding that the PD was "in tatters".
Bersani had been the target of growing criticism after he threw away a big lead in the opinion polls ahead of the February elections.
He said he would step down as soon as a new president was elected and his deputy Enrico Letta was expected to take over interim powers.