Somalia's parliament has overwhelmingly approved Ali Mohammed Gedi as prime minister, 12 days after sacking him.
President Abdullahi (l) and Prime Minister Gedi (r) are from rival clans
The parliament had originally passed a vote of no confidence in him, on the grounds that he and his cabinet had not been endorsed by MPs.
He was also accused of not sticking to clan-based quotas in his cabinet, but President Abdullahi Yusuf reappointed him two days later.
Somalia has been without a functioning national government for 13 years.
After being sworn in on Thursday, Mr Gedi thanked the parliamentarians for officially approving his appointment with a large majority.
"Now I will form the government after wide consultations with each of you," he said.
On 3 December, parliament rejected Mr Gedi's cabinet line-up because it did not reflect a fair distribution of power among the war-torn country's five clans.
A minister and five deputy ministers then resigned from the government, saying the cabinet was too large and not representative.
Mr Gedi has one month to choose a new cabinet and submit it to parliament for approval.
"Now the message is clear. If the president and the prime minister act in accordance with the law, they will enjoy full support of parliament," AFP news agency quoted parliamentary speaker Shariff Hassan Sheik Adan as saying.
Correspondents had praised the choice of Mr Gedi as prime minister in November, as the academic comes from a rival clan to Mr Abdhullahi - the Hawiye, which controls the capital, Mogadishu.
During the past 13 years, rival warlords have battled for control of the country and Somalia has been divided into a patchwork of fiefdoms.
All the major warlords are involved in the two-year peace process in neighbouring Kenya which led to President Abdullahi's election, raising hopes that Somalia could soon return to normal.
The new Somali parliament and government are based in the Kenyan capital, Nairobi, because Mogadishu is still considered too dangerous.