Somali lawmakers gathered behind the blast walls of the capital's airport on Wednesday to elect their president, after months of delays and following threats from Islamist insurgents bent on derailing the process.
The protracted vote began with 14,000 elders and prominent regional figures choosing 275 members of parliament and 54 senators, who in turn now choose whether to back President Hassan Sheikh Mohamud for a second term or one of 21 rivals.
The presidential vote, which was originally slated for August, is due to start at about noon (0900 GMT). It is likely to take several rounds before a winner is declared.
President Mohamud, who has led the country since 2012 in the effort to rebuild after more than two decades of war and chaos, has the support of about a third of lawmakers, experts say, giving him an edge but not a guarantee of victory.
The threat from Islamist al Shabaab rebels, who regularly launch attacks in Mogadishu and elsewhere, meant the government and its Western backers scrapped a plan to give each adult a vote due to the challenge of securing polling stations.
Several blasts, probably from mortar bombs, echoed across the seaside capital Mogadishu late on Tuesday. But there were no reports of casualties in the city, which had been subject to a security lock-down in the build up to the vote.
Earlier on Wednesday, the group's militants stormed a hotel in the semi-autonomous Puntland region, further north up the coast, killing four guards. Two attackers also died.
Rival presidential candidates have accused each other of buying the loyalty of lawmakers, drawing furious denials. Anti-corruption group Marqaati says tens of thousands of dollars have been handed to individuals to secure support in the vote.
Western donors, who have often criticised President Mohamud's government for corruption, say the vote is far from perfect but say it marks a modest step forward from 2012 when just 135 elders picked the lawmakers, who chose the president.
The airport, where the vote is taking place, is guarded by the African Union peacekeeping force AMISOM and is surrounded by high concrete barriers to protect it from attack. U.N. agencies and foreign embassies are located in the compound.
Al Shabaab, which had ruled Somalia for several years, has been slowly driven out of its major strongholds in a campaign by AMISOM and Somali troops. But its fighters continue to launch regular gun and bomb attacks in their bid to topple the government and impose their strict interpretation of Islam.
Get the latest news and updates on elections in Africa by Following us on twitter @africanelection and like our facebook page