All but three lawmakers in parliament voted to approve President Hassan Sheikh Mohamud´s nomination of the economist who has worked with several international organisations and banks.
Three abstained from voting, and none opposed.
“A total of 243 out of the 246 gave a vote of confidence to the new prime minister,” said parliamentary speaker Mohamed Osman Jawari.
Ahmed, 54, faces a giant task to rein in corruption, crush Al-Qaeda-linked Shebab insurgents battling to topple the central government, and rebuild the troubled Horn of Africa nation.
“I´m very grateful with parliament for endorsing my nomination,” the new prime minister said after the vote.
“I promise to work for the development of the country, and to form a cabinet of high quality soon.”
A dual Somali-Canadian citizen, Ahmed holds a doctorate in trade and development from Ottawa university and speaks multiple foreign languages.
He replaces Abdi Farah Shirdon, ousted by parliament after just over a year in the post amid fierce power struggles within the internationally-backed government.
Ahmed comes from the same clan as Shirdon, which is likely to appease supporters of the former prime minister.
In Somalia´s complex politics, each community expects to be represented in the corridors of power.
He now has 30 days to appoint a new cabinet, which must then be approved by parliament.
The Somali government which took power in August 2012 was the first to be given global recognition since the collapse of the hardline regime in 1991, and billions of dollars in foreign aid have since poured in.
It was hailed as offering the best chance for peace in a generation, replacing a transitional leadership mired by ineffectiveness and rampant corruption.
But political wrangles and reports of corruption have raised concerns the government, like the last administration, is trapped by infighting.
While the government controls the capital Mogadishu, large swathes of rural areas are controlled by the Shebab, who have emerged as a threat to regional peace.
They have struck outside of Somalia, most recently at the upscale Westgate shopping mall in Nairobi in a four-day September raid that killed at least 67 people.