BEIRUT - Lebanon's parliament elected the army commander, Gen. Michel Suleiman, as president yesterday, filling a post vacant for six months and bringing a symbolic if tenuous end to the country's worst crisis since the 15-year civil war ended in 1990.

The vote for Suleiman was virtually uncontested, already agreed to in a deal negotiated in Qatar last week that ended an 18-month confrontation between forces allied with the government and the opposition led by the Shiite Muslim movement Hezbollah. Postponed 19 times, the election marked the first step in reconstituting what had looked more and more like a failed state in past months: an unfilled presidency, a cabinet deemed illegitimate by the opposition, and a parliament that had not met since 2006.

After Suleiman's election, by 118 votes of 127 possible, a flag-waving crowd that had gathered in his hometown of Amchit erupted in cheers. Fireworks detonated over Beirut, cars blared their horns, and church bells tolled. Staccato bursts of celebratory gunfire rattled across a capital that, less than two weeks ago, witnessed pitched gun battles redolent of civil war.

"I call upon all of you, politicians and citizens, to begin a new stage that is called Lebanon and the Lebanese," Suleiman, who forewent his military uniform for the civilian suit of a politician, told parliament. To repeated rounds of applause, he said the country had paid dearly for what he called national unity. "Let us preserve it hand in hand."

The deal that brought Suleiman to power represented another setback in the region for the United States, which has long sought to isolate Hezbollah, a group backed by Syria and Iran. Under the agreement, Hezbollah and its allies will have veto power in the coming cabinet - the group's demand since the crisis began after a war with Israel in 2006 - demonstrating its clear role today as the single most powerful force in Lebanon.

Suleiman, 59, was appointed army commander in 1998, when Syria still exercised tutelage over Lebanon. He rose through the ranks of an army that, particularly in the 1990s, worked closely with Syria and Hezbollah.

The vote represented a rare moment of consensus across the political, social and ideological divide that still fractures Lebanon - from the country's posture toward Israel to which foreign patron will play the greatest role in Lebanese politics, long vulnerable to regional crises. The foreign ministers of Iran, Syria, Saudi Arabia and France attended the parliamentary session, as did the emir of Qatar, who was seated at the podium of parliament in recognition of his government's role in the negotiations, which nearly collapsed twice. In a telling sign, the United States was represented only by a congressional delegation.

"This last crisis ended with a winner and a vanquished," said the emir, Sheik Hamad Bin Khalifa al-Thani. "The winner is Lebanon, and the vanquished is the feud, and this needs to be clear to all - today, tomorrow and forever."

Streets in the capital and elsewhere yesterday were awash in Lebanese flags and posters celebrating Suleiman's presidency. "The leader, the president," one read. "Congratulations, Lebanon," said another. Weary of almost continuous crises that have beset Lebanon since former Prime Minister Rafiq al-Hariri was assassinated in a 2005 car bombing in Beirut, many residents, regardless of their stance on the crisis, have greeted the agreement and election of Suleiman with relief that the country averted civil war, consolation perhaps muted by frustration that the confrontation lasted as long as it did.