Mohammed Abdullahi Farmajo, a US-educated former prime minister, was sworn in as Somalia's new president Wednesday after lawmakers gave him an unassailable lead in the second round of an election in Mogadishu.
Celebratory gunfire erupted across the city shortly after Farmajo was declared the winner of Wednesday’s vote.
Outgoing President Hassan Sheikh Mohamud conceded defeat as it became clear he could not win a third round.
"History was made, we have taken this path to democracy, and now I want to congratulate Mohamed Abdullahi Farmajo," Mohamud said.
"This is a victory for Somalia and the Somalis," Farmajo told lawmakers moments after he was sworn into office.
Mohamud held a slight lead over Farmajo, 88 votes to 72, after the first round of 21 candidates, but Farmajo held a clear lead after the second round among the three candidates remaining.
An election in a secure airport
The election took place in Mogadishu’s tightly secured airport amid threats from extremist group al-Shabaab, with a security lockdown closing the capital's international airport and cleared major streets.
Fears of attacks by Islamic extremist group al-Shabaab limited the election to the country's legislators, who voted in two rounds.
This Horn of Africa nation is trying to put together its first fully functioning central government in a quarter of a century. Years of warlord-led conflict and al-Shabaab attacks, along with famine, have left this country of about 12 million people largely shattered.
Somalia's instability landed it among the seven Muslim-majority countries affected by US President Donald Trump's executive order on immigration, even though its government has been an increasingly important partner for the US military on counterterrorism efforts.
In a sign of the dangers that remain in the capital, Mogadishu, two mortar rounds fired by suspected extremists late Tuesday hit near the election venue.
Examples included violence, intimidation and men taking seats that had been reserved for female candidates, the joint statement said.
With reports of votes being sold for up to $30,000 (€28,000) apiece, "this is probably the most expensive election, per vote, in history", the Mogadishu-based anti-corruption group Marqaati said in a report released Tuesday.
Many of the candidates, including Farmajo, also hold foreign passports, underlying the decades of instability that has seen Somalis fleeing to neighbouring Kenya as well as the US, UK and several other West European countries.
Various Muslim-majority countries seek a friendly Somali government, including Turkey, which has invested heavily in the country. The United Arab Emirates and Qatar are backing different candidates.