Lebanon’s parliament has elected a former army general as president, after a surprising shift in allegiances across the country’s deeply divided political parties.

A vote at midday – the 46th since President Michel Suleiman stepped down at the end of his term in May 2014 – produced the neccessary two thirds majority in favour of electing former army official Michel Aoun on Monday. Fireworks were set off by supporters around Beirut, with celebrations expected throughout the afternoon and evening in Christian neighbourhoods.

Mr Aoun, an 81-year-old Christian nicknamed "The General", won the surprise support of two of his oldest and most bitter rivals as Beirut’s politicians saught an end to the stalemate which has prevented legislation from being passed for more than two years.

Both Samir Geagea, leader of the Christian Lebanese Forces, and Sunni former premier Saad Hariri, endorsed Mr Aoun, as well as his long-time ally, Shiite movement Hezbollah.

Mr Hariri, who has in the past accused Mr Aoun of being in league with Syrian elements accused of assassinating his father Rafic Hariri in 2005, said he decided to support his former rival as all other options had been exhausted, adding that Lebanon needs protecting from the Syrian crisis next door.

He described his surprise endorsement last week as necessary to “protect Lebanon, protect the [political] system, protect the state and protect the Lebanese people”.

Analysts suspect the two made a deal which could mean the return of Mr Hariri as prime minister, a realpolitik move designed to ensure both men's politlcal careers endure.

Mystery of a death on the Beirut road Show all 3 1 /3 Mystery of a death on the Beirut road Mystery of a death on the Beirut road beirut1.jpg Iranians carry the coffin of Hassan Shateri AFP Mystery of a death on the Beirut road beirut3.jpg General Shateri AFP Mystery of a death on the Beirut road beirut2.jpg Iranian Ambassadorto Beirut, Ghazanfar Roknabadi AFP

Under Lebanon’s constitution, the president must be a Maronite Christian, the prime minister a Sunni Muslim, and the speaker of parliament a Shiite Muslim.

The biggest obstacle for electing Mr Aoun was strong opposition from speaker Nabih Berri, who instructed the 13 members of his Amal party not to vote for him.

The vote occured under strict security measures: business in downtown Beirut, an area already full of barbed wire and army-run checkpoints even during calmer times, were closed on Monday, and all but essential traffic banned from the city centre.

Metal detectors have been set up for anyone trying to pass through the streets around parliament, and army helicopters are flying overhead.