Farmajo, 54, won the election won after two rounds of voting by the Somali parliament in Mogadishu. Former president Sharif Sheikh Ahmed was third with 49, and Prime Minister Omar Abdirashid Sharmarke was fourth with 37.
"History was made, we have taken this path to democracy, and now I want to congratulate Mohamed Abdullahi Farmajo", Mohamud said.
As the result of the election was announced, celebrations erupted across the capital.
He served as prime minister for only eight months between 2010 and 2011.
Somalia's groundbreaking presidential election neared the end of a second round Wednesday after the number of candidates dropped from 21 to three, while a security lockdown closed the capital's worldwide airport and cleared major streets.
Originally set for October 30, the presidential vote was delayed four times as clan elders jockeyed for lawmaker posts and the auditor-general alleged that as much as $1.3 million changed hands for some individual seats, the securing of which could sway the presidential election.
The election took place under heavy security amid threats from extremist group al-Shabab, with a security lockdown closing the capital's global airport and clearing major streets.
Outgoing President Hassan Sheikh Mohamud, whose administration faced public and Western criticism for corruption scandals, conceded defeat as it became clear he could not win in a third round of voting.
Donald Trump's Army Secretary Nominee Has Reportedly Withdrawn His Name From Consideration
Viola has now become the first of Trump's nominees for Cabinet positions to withdraw himself from consideration for a post. Earlier this month The New York Times reported that Viola was once accused of punching a concessions worker at a racetrack.
"This is a milestone for Somalia's history", Mohamed told lawmakers and worldwide representatives gathered at a hangar in Mogadishu's airport, where he took the oath of office shortly after he was declared victor.
In northeastern Somalia, suspected al-Shabab militants launched an attack at dawn Wednesday on a hotel in the Red Sea port town of Bosaso.
On his Facebook page, Farmajo says that while premier, he implemented the first monthly stipends for soldiers, worked on the country's new constitution and sent delegations to defuse clan-related tensions in several regions.
He eventually became a US citizen, served as equal employment commissioner for the NY state Transportation Department and wrote a master's thesis titled: "U.S".
As long as the candidate is a Somali citizen and Muslim, Somalia's constitution (p. 28) doesn't specify much about foreign passport holders, and whether or not they are eligible to run for president.
The scale of corruption means the elections have been a PR victory for al-Shabab, which have been seen to be above the backdoor politics.
TRT World's Fidelis Mbah brings more information on Somalia.
The worldwide community pushed Somalia to hold the election as a symbol of strength, with the US pouring in hundreds of millions of dollars in recent years for political and economic recovery. A joint statement by the United Nations, U.S., European Union and others cited a number of "egregious cases of abuse of the electoral process, including seats reserved for women candidates only that were ultimately taken by male candidates".