The Lebanese parliament elected former army commander Michel Aoun as president on Monday, ending a 29-month presidential vacuum as part of a political deal that is expected to make Sunni leader Saad al-Hariri prime minister.
Aoun, who is in his 80s, secured the presidency by winning the support of at least 65 MPs, or an absolute majority of the members of the 128-seat chamber.
In a speech, Aoun vowed to fight terrorism and to prevent regional "fires" spreading to Lebanon.
He said his government would tackle terrorism "preemptively and preventively" until it was uprooted.
Aoun also said that any solution to the war in neighbouring Syria must guarantee the return of Syrian refugees in Lebanon, who Lebanese officials say number 1.5 million. Syrian camps in Lebanon must not turn into militant hideouts, he said.
Fireworks echoed across Beirut as the tally showed Aoun the winner. Aoun, an MP, was shown smiling in his seat. The Lebanese presidency is reserved for a Maronite Christian in the country's sectarian power-sharing system.
Hariri's decision to endorse Aoun marked a major political concession reflecting the diminished role of Saudi Arabia in Lebanon, and the decisive influence wielded by the Tehran-backed Hezbollah.
Saudi Arabia had backed Hariri and his allies through years of political struggle with Hezbollah and its allies.
Hariri's own financial misfortunes have also played a big part in bringing about the breakthrough. His political network in Lebanon was hit by a cash crunch caused by financial troubles at his Saudi-based construction firm, Saudi Oger.
Analysts say the position of prime minister, which he previously held from 2009 to 2011, should help him shore up his support ahead of parliamentary elections that are due to be held next year.
Aoun is due to meet MPs later this week on their preferences for prime minister. He is obliged to designate the candidate with the greatest support among MPs, expected to be Hariri.