Italy's lawmakers re-elected 87-year-old President Giorgio Napolitano in a bid to break the country's political gridlock, as protestors outside parliament jeered the result.
The ex-communist Napolitano won with a sweeping majority of 738 ballots out of 1,007 possible votes - well ahead of leftist academic Stefano Rodota, backed by the anti-establishment Five Star Movement, who scored 217.
But hundreds of people rallied in Rome at a protest called by Beppe Grillo, the leader of the Five Star Movement, shouting "Jokers!" "Shame!"
Grillo's party came third in February elections, shaking up the traditional political system, and his supporters were angry that their candidate Rodota had been rejected by the two main political blocs on the right and left.
Although former comedian Grillo had been scheduled to join the demonstration, he later reconsidered. But in a blog post, he condemned Napolitano's re-election as a "coup d'etat" by the mainstream parties.
In a posting earlier this week, Grillo remonstrated with leftist leader Pier Luigi Bersani, demanding to know why he refused to back Rodota.
"Too well-educated? Too independent? Too honest? Too popular?" he taunted. "Too much like the president of everyone?"
By Friday however, Bersani had become another casualty of Italy's political deadlock, saying he would step down once a new president was elected.
He announced his impending departure after a rebellion within his own ranks stopped two presidential candidates he had backed - former European Commission president Romano Prodi and former trade union leader Franco Marini - from getting enough votes.
Napolitano's re-election finally broke the deadlock.
But he had only agreed to stand for an unprecedented second term on Saturday, after pleas from outgoing prime minister Mario Monti, rightist leader Silvio Berlusconi and Bersani.
Later, at a brief ceremony in the presidential palace after he was voted back in, he called on bickering politicians to "honour their commitments" after a "tormented" presidential election process.
"We must all bear in mind, as I have tried to do, the difficult situation of the country," he said.
US President Barack Obama congratulated Napolitano, praising his "extraordinary leadership".
"I admire his decision to once again serve the Italian people as president, and welcome the decision that the Italian parliament has made to come together to select him for continued service," he said.
Monti also said he had called Napolitano to thank him for his "spirit of sacrifice" during "a difficult phase of our nation's life".
European Commission President Jose Manuel Barroso said Napolitano would provide "a decisive contribution to our common European ideal".
And Pope Francis hailed his election, saying Napolitano's actions had been "illuminated and wise".
The president will be officially sworn in on Monday in the lower house of parliament and begin sensitive talks on setting up a new government.
The problem he faces is that neither one of the country's main political forces, grouped around Bersani's Democratic Left and Berlusconi's People of Freedom Party, emerged as a clear winner in February's general election.
That has left the eurozone's third largest economy in political limbo, leaving Monti's cabinet to limp on with only interim powers. The reform plan Monti launched is now at a standstill.
Analysts expect either a technocratic government similar to Monti's one, or a grand coalition - but that would prove controversial among many Italians as it could bring the scandal-tainted Berlusconi back to power.
Napolitano is at least considered as being above the party political fray and is respected by the rival forces.
As recently as last week he had ruled out staying on, saying he had done what he could to break the political stalemate and after seven years in office was looking forward to retirement.
He may not serve out his full second term, but step down once he has helped broker a functioning government, ending a political career that he began in the World War II as an anti-fascist activist.
Napolitano was credited with engineering former European commissioner Monti's rise to power after the then premier Berlusconi was pushed out of power in 2011 to calm a wave of panic on the financial markets.
While the Italian presidency is usually a ceremonial role, during times of political instability it takes on far greater importance.