Former Prime Minister Mohamed Abdullahi Mohamed "Farmajo" is the new president of Somalia.
The ex-premier emerged the winner in the second round of voting but did not garner the two-thirds votes required to clinch the presidency.
However, the incumbent Hassan Sheikh Mohamud conceded defeat, eliminating the need for a third round for which a simple majority would have seen the winner declared president.
Mr Farmajo, as he is commonly known, lead in the second round with 184 votes ahead of Mr Mohamud's 97 followed by former president Sharif Sheikh Ahmed with 46.
The 55-year-old who holds Somali and US citizenship was sworn in as president immediately after Mr Mohamud dropped out of the contest.
A total of 24 candidates had declared interest in running for presidency but only 21 contested during the Wednesday vote.
Eighteen contestants dropped from the race after the first round leaving the three to face off in the second voting round.
The election was carried out at an airport hanger in Mogadishu amid tight security and lockdown of the city. There were fears that the Al Shabaab terrorist group would try to disrupt the election that has been delayed four times over security and logistical challenges.
Members of the bicameral Parliament elected the president as the country prepares for one-person one-vote in 2020.
Unlike 2012 when the president was elected by 135 clan elders, the current election initially involved 14,024 persons designated by the elders, who picked 275 MPs and 54 senators.
The Horn of Africa nation is trying to rebuild an effective central government after more than three decades since President Siad Barre’s military regime was overthrown in 1991.
Terrorism, clan rivalries, economy and food insecurity are among the top concerns of the more than 10 million Somali population that the new president will seek to address.
Mr Farmajo served as the prime minister from 2010 to 2011 when he was forced to resign after disagreement between him and then-president Ahmed.
His removal was part of a UN-backed deal that extended the mandates of the president, the speaker and deputies to 2012 when new elections were to be organised.
Mr Farmajo, a named he earned for loving to eat cheese when he was young, was not popular with other politicians. He portrayed himself as a man of the people, travelling economy class when he went on trips abroad.
Of the more than 20 other candidates, he was the most popular on social media – as he was regarded as a nationalist.
His main rivals were criticised for having the backing of either Ethiopia or Kenya.
Celebratory gunfire erupted across Mogadishu at his victory including in border towns near Kenya. In Nairobi, Kenya's capital, people could be seen marching and singing in jubilation in Eastleigh district, a suburb, after he was declared president.
Kenya host thousands of Somalis who have fled instability in their country with most of them living in the Dadaab refugee camp close to the border between the two countries.
Mr Farmajo was born in Mogadishu in 1962.
He moved to the US in 1985 to work at the Somalia Foreign Affairs department in Washington DC.
He later enrolled at the University of Bufallo in New York for his bachelor's degree in 1989, and went on to attain a master's degree in political science in same institution in 2009.
Mr Farmajo applied for political asylum in the United States after collapse of the Mogadishu government in 1991.