There has been a mixed reaction in the Somali capital, Mogadishu, to the election of a new president following 13 years of war.
The new president's first task is to appoint a prime minister
Some are delighted with the election of Abdullahi Yusuf, seeing him as a strongman who can bring law and order.
But a huge rally which had been called in celebration has been cancelled due to security concerns.
Mr Yusuf was chosen by members of the interim parliament in Kenya, because Somalia was considered to be unsafe.
After he was announced the victor of the elections, his supporters in his home area of Puntland took to the streets to celebrate.
But the BBC's Mohammed Olad Hassan in Mogadishu says that some residents are afraid that disappointed warlords might start fighting.
Thousands of people in Somalia watched the election live on television or listened on their radios.
Some fired their guns in the air to celebrate his victory and there were loud cheers in the Nairobi sport stadium where the election was held when the results were declared.
"This is a wonderful day for our region, a wonderful day for the people of Somalia," said the chief mediator in the talks, Bethwel Kiplagat.
The election followed two years of peace talks
But he warned that a lot of hard work was still needed to rebuild the shattered country.
"People should not see this as an end but as the beginning of a greater task ahead of us," he said.
Businesswoman Asha Alasow, who had been a staunch supporter of a Mogadishu warlord, welcomed Mr Yusuf's election.
She said that the years of division had led to "nothing but destruction".
Sixty-eight year-old Abdi Mohamed Igal said that after all the fighting, he would support whoever was elected.
But another Mogadishu resident, Abdi Awkombe, will not be happy until guns disappear from the streets.
"There are still armed militias... so it would be very difficult for the ordinary people in Mogadishu to express their feeling in public," he said.
After two rounds of voting and three voluntary withdrawals, the field was narrowed down from 28 to just two candidates.
Abdullahi Yusuf, a military strongman and president of the semi-autonomous Somali region of Puntland, went head-to-head with Abdullahi Adow, a financier and former ambassador to Washington.
After the final third round, Abdullahi Yusuf emerged the winner by securing 189 votes against 79 for his run-off rival.
Mr Adow immediately backed the victor.
"The right man had been elected to be president of Somalia," he said.
"I know him from a long long time and I am confident that he will fulfil the trust the Somalis have put in him," he said.
Decade of chaos
The 275 MPs, most of them clan leaders and warlords, had earlier queued to go through metal detectors and enter Nairobi's Kasarani Sports Centre Gymnasium.
The new president's first job will be to choose a prime minister, our correspondent says.
In faction and clan-ridden Somalia, this decision will be made after considerable horse-trading, much of which has been going on in the corridors and backrooms of the sports hall.
Abdullahi Yusuf is not expected to return to Somalia for at least two months, our correspondent says.
The stadium was packed while thousands more Somalis gathered outside where heavily armed Kenyan police were patrolling the venue.
Somalis are hoping that a new administration under a new president and prime minister will set them on the road to peace and stability.
But optimism is tempered by the knowledge that there have been numerous failed attempts to restore stability, correspondents say.
Somalia descended into chaos as rival militias tore the country apart after the military ruler Mohammed Siad Barre was overthrown.
Many of the two million Somalis who fled became refugees in neighbouring countries.