Somali Prime Minister Abdi Farah Shirdon has lost a vote of confidence in parliament after 13 months in office, in what is seen as a blow to efforts to stabilise the country.
He fell out with President Hassan Sheikh Mohamud last month after he tried to sack some of the president’s allies from the cabinet.
Mr Mohamud took office in 2012 in a UN-backed move to end years of conflict.
Islamist militant group al-Shabab still controls many areas.
Pro-government forces, including those of the African Union, have pushed the militants out of most of the country’s major cities over the past 18 months.
But al-Shabab continues to stage attacks.
‘Coming of age’
Before the vote, Mr Shirdon told the BBC he would accept the outcome in order to support the country’s “weak” institutions.
He lost by 184 votes to 65.
BBC Somali analyst Abdullahi Abdi Sheikh says this brings to an end a dispute between Somalia’s two political leaders, which has paralysed government activities for several weeks.
The president now has 30 days to appoint a new prime minister.
Many Somalis blame the country’s constitution for the political struggle, since there is confusion over the division of power between president and prime minister, our analyst says.
But UN Somalia envoy Nicholas Kay said it was progress that the wrangle had been settled according to the constitution.
“Somalia’s institutions are coming of age,” he said.