Former prime minister Mohamed Abdullahi Farmajo has been elected Somalia's new president after two rounds of voting by members of parliament.