A tribal-based parliament made up mainly of military commanders and tribal leaders has selected a head of state with the huge task of establishing the first legitimate government in 13 years.
After a third round of voting by members of Somalia's transitional assembly in Nairobi on Sunday, election officials said Yusuf had won 189 votes against 79 for his run-off rival, Abd Allah Ahmad Adu, a former diplomat and finance minister.
Yusuf had served as president of the autonomous north-eastern region of Puntland since 1998.
At least three hours behind schedule, lawmakers queued up to go through metal detectors and enter a national sports complex that served as the parliament.
The building was ringed by paramilitary police armed with assault rifles.
The vote is the culmination of two years of peace talks designed to create a new transitional government intended to shepherd Somalia to elections after five years.
Thirteen previous peace conferences have failed to stabilise the country of seven million, which is divided into clan-based regions.
The first person to cast a ballot was assembly speaker Sharif Hasan Shaikh Adan.
He told reporters beforehand that in order to stand, candidates would have to first sign a solemn pledge to respect the result and hand over to the new government any weapons held by them or their supporters.
The parliament is made up of
commanders and tribal leaders
They would also have to promise not to disrupt the voting process itself, he said.
Among the many possible pitfalls the 275-strong parliament faces is the danger that a sore loser could decide to play a spoiling role, as the new president prepares to establish his rule in Mogadishu.
"If this government goes to Somalia without a consensus among the participants, particularly those with big guns, it will be very difficult to do anything good on the ground," said Somali analyst Jibril Ibrahim Abd Allah.
Two of the 27 candidates - regional commanders Jama Ali Jama and Hasan Muhammad Nur Shatigudud - dropped out of the race without explanation on Sunday.