The Somali parliament on Monday voted to endorse Prime Minister Nur Hassan Hussein and his government, overturning President Abdullahi Yuruf Ahmed's decision to sack the prime minister.
In a no-confidence vote in the parliament, 143 out of the 170 lawmakers voted for the government, 20 voted against it and seven abstained.
The Somali president sacked the prime minister on Sunday, accusing him of incompetence, embezzlement and mismanagement.
The two senior Somali leaders have been in deep disagreement over a variety of issues including the way Somali national reconciliation is being handled.
Soon after the sacking on Sunday, the prime minister rejected the decision by the president.
Speaking in the southern town of Baidoa, the seat of the parliament, Hussien said that the president has no "legal authority" to sack him and that he would continue to serve in his capacity as prime minister.
"I do not accept the president's announcement today that he sacked me as prime minister because he does not have that legal authority in our charter," Hussein, who was appointed prime minister in November 2007 to replace Ali Mohamed Ghedi, said at a press conference.
The African Union (AU) has called on the two sides to bridge their differences and join efforts to work for the interests of the country and its people.
In a statement issued late Sunday, AU Commission Chairman Jean Ping said the sacking of the prime minister would undermine efforts to bring peace and further weaken the fragile transitional government of Somalia.
Ping said the dismissal of the prime minister will "further complicate the situation and deepen the rift within the Transitional Federal Government (TFG)".
Somalia has not had a functioning national government since President Mohamed Siad Barre was overthrown in 1991.