A former Somali president has been returned to the nation's top office after defeating the incumbent leader in a protracted contest decided by legislators. A third round of voting proved decisive for Hassan Sheikh Mohamud late on Sunday. He had previously served as president between 2012 and 2017, before being voted out of office. Members of the upper and lower legislative chambers picked the president in secret balloting at the Halane military camp, which was protected by African Union peacekeepers. The first round of voting had been contested by 36 aspiring presidents, four of whom proceeded to the second round. With no candidate winning at least two thirds of the 328 ballots, voting then went to a third round in which a simple majority was enough to identify the winner. Mr Mohamud’s election ended a long-delayed electoral process that had raised political tension. President Mohamed Abdullahi Mohamed’s mandate expired in February 2021 without a successor in place. Mr Mohamed and Mr Mohamud sat side-by-side on Sunday, watching calmly as the ballots were counted. Celebratory gunfire rang out in parts of the capital Mogadishu as it became clear that Mr Mohamud had defeated the man who replaced him. Mr Mohamed conceded defeat and his successor was immediately sworn in. Returning to power, the 66 year old is the leader of the Union for Peace and Development party, which commands a majority of seats in both legislative chambers. He also is well-known for his work as a civic leader and promoter of education, including for his role as one of the founders of Mogadishu’s Simad University. The Somali government under Mr Mohamed faced a May 17 deadline to hold the vote or risk losing funding from international partners. Mr Mohamed — who is also known as Farmaajo because of his appetite for Italian cheese — said on Twitter while voting was under way that it was “a great honour to lead” Somalia. For Mr Mohamed and his supporters, Sunday’s loss will be disappointing after he rose to power in 2017 as a symbol of a Somali diaspora eager to see the country prosper after years of turmoil. He leaves behind a country even more volatile than he found it, with a reported rift in the security services and the constant drumbeat of Al Shabab attacks. Analysts had predicted that Mr Mohamed would face an uphill battle to be re-elected. No sitting president has ever been elected to two consecutive terms in this Horn of Africa nation, where rival clans fight intensely for political power. In winning the vote, however, Mr Mohamud overcame the odds as no former president had ever launched a successful return to the office. A member of the Hawiye clan, one of Somalia’s largest, Mr Mohamud is regarded by some as a statesman with a conciliatory approach. Many Somalis hope he can unite the country after years of divisive clan tensions but also take firm charge of a federal government with little control beyond Mogadishu. Mr Mohamud promised during campaigns that his government would be inclusive. He also acknowledged the mistakes of his previous government that faced multiple corruption allegations and was seen as aloof to the concerns of rival groups.