For almost two-and-a-half years, Lebanon - politically split along sectarian fault lines - has been without a president.
Michel Aoun, Christian leader and founder of the Free Patriotic Movement, and for a long time one of the main contenders, has since 2006 been an ally of the Iranian-backed Shia party, Hezbollah - formerly a bitter political opponent of Mr Aoun.
That alliance was sufficient to make him persona non grata for the main Sunni political group in the country, the Future Movement, led by former Prime Minister Saad Hariri and with strong links to Saudi Arabia.
A standoff, which became known as the "presidential vacuum", ensued, effectively paralysing the country since May 2014.
On Monday, Mr Aoun was finally elected to the presidency with, remarkably, the support of the Future Movement.
The elections followed dramatic shifts in positions and endorsements of the major parties, which left many observers trying to understand the new dynamic extremely puzzled.
Saad Hariri's decision to change course came after an agreement was reached between him and Michel Aoun.
Few details are known about the terms of the deal, apart from a pledge to appoint Mr Hariri as prime minister in exchange for him dropping his opposition to Mr Aoun's candidacy.
In Lebanon, a newly elected president appoints a prime minster following consultations with MPs. The prime minister then starts the task of forming a new cabinet.
But what prompted Saad Hariri's change of heart? There is no simple answer, though several explanations have been circulating.
One was offered by Mr Hariri himself, who spoke of a "sacrifice to save the state from total collapse".
The presidential vacuum had developed into a legislative crisis when parliament ceased to pass laws after a large group of MPs decided that electing a president should take priority over any other vote.
It has also deeply affected the work of the cabinet, which was caught in disputes over how to proceed with decision-making in the absence of the head of state, who has the right to preside over the cabinet sessions.
Another explanation put forward concerns the financial and political problems of Mr Hariri, a billionaire whose business interests in Lebanon and abroad are reported to be in deep trouble.
Mr Hariri is facing mounting anger from unpaid staff and a crisis in overdue loans, amid uncertainty about the future of his companies. He also faces an increasingly unhappy and disappointed popular base that feels neglected and ignored by its leader.
In this context, his endorsement of Michel Aoun might have been his only way back to the office of prime minister, and therefore a chance to salvage his leadership.
But whatever the reason, it is highly unlikely that Mr Hariri could have made this move without foreign endorsement, especially from Saudi Arabia, his main regional backer and staunch foe of Hezbollah.
In an interview given to a local TV channel, Mr Hariri seemed confident of international backing for what he called a "new era" for Lebanon.
He was speaking as a senior Saudi envoy was visiting the country and conveying a message of support to Lebanon, regardless of the identity of the new president.
The message was interpreted as a signal that Saudi Arabia would not oppose the choice of Michel Aoun, though many Lebanese are still trying to decode the Saudi rationale.
Although the political vacuum is now ended, another issue is fast becoming a concern - whether Saad Hariri will be able to form an inclusive and workable cabinet.
He is already facing stiff opposition from Nabih Berri, the Shia speaker of parliament and one of the most powerful politicians in the country.
Mr Berri was opposed to the Aoun-Hariri deal and has clearly stated he will not take part in the coming government.
While common ground might have been found between the different players, the reality is that a new government would be at best a marriage of convenience among parties with major differences, not least in their support for rival sides in the wars raging in the region, and thus, might be seriously tested very soon.
The president has finally been elected but the crisis might not be over.