Italy's president Giorgio Napolitano has agreed to stand for another term in office after the parliament failed in its fifth attempt to elect a successor.

Mr Napolitano, 87, was due to retire next month, but politicians from rival parties appealed to him to renew his seven-year mandate.

He won with a sweeping majority of 738 ballots out of 1,007, to cheers in parliament.

He is not expected to serve the full term, but only stay until parliament can agree on a new president to end the political deadlock in the country.

Italian MPs have voted five times since Thursday with no clear winner.

The main centre-left coalition narrowly won elections in February, but did not win enough votes for an overall majority in parliament.

Since then, the cabinet of outgoing prime minister Mario Monti has limped on with only interim powers.

"We must all bear in mind, as I have tried to do, the difficult situation of the country," Mr Napolitano said after being handed the election results in the presidential palace.

He called on bickering politicians to "honour their commitments".

Mr Monti said he had called Mr Napolitano to thank him for his "spirit of sacrifice" during "a difficult phase of our nation's life".

European Commission president Jose Manuel Barroso congratulated him, saying he would provide "a decisive contribution to our common European ideal".

The Vatican's official newspaper, the Osservatore Romano, called him a "true resource".

But news of Mr Napolitano's re-election was not welcomed by everyone.

Hundreds of people rallied outside the presidential palace and denounced it as a coup d'etat, with protesters shouting: "Jokers! Thieves! Shame!"

The protest was called by comedian-turned-politician, Beppe Grillo, whose Five Star Movement party came third in February's election.

But Mr Napolitano is considered as being above the party political fray and is respected by rival forces.

He will be officially sworn in on Monday in the lower house of parliament and begin sensitive talks to set up a new government.

He is a former top Italian Communist Party official, credited with engineering Mr Monti's rise to power after then premier, Silvio Berlusconi, was ousted during a wave of panic on the financial markets in 2011.