Thursday's vote was an overwhelming majority: some 229 lawmakers of the 275-member clan-based assembly approved in the Kenyan capital, Nairobi a motion recognising Gadi as prime minister.
Six voted against, 24 abstained and 16 were absent.
Immediately afterwards, the speaker of the House swore Gadi into office as Somali President Abd Allah Yusuf Ahmad looked on.
On 11 December, the parliament passed a motion sacking Gadi and his government, saying he was illegally in office because Yusuf had failed to seek parliamentary approval. Two days later, the president reappointed him.
"It's good for all of us to accept the PM and give him time to form the government," Yusuf Ahmad told the lawmakers.
Earlier cabinet rejected
"I thank all members of parliament for approving me as prime minister," Gadi said.
"Now, I will form the government after wide consultations with each of you."
The East African nation has been
shattered by clan fighting 1994
His earlier cabinet, which was formed on 3 December, was rejected because it was not based on the principle of power-sharing stipulated in Somalia's Transitional National Charter, a sort of interim constitution.
The swearing-in ceremony took place against the backdrop of publication of a statement by the International Crisis Group (ICG) in Nairobi on Thursday.
It said the new government, which is still based in Nairobi due to insecurity in Mogadishu, will fail if it does not address issues that have divided Somalis for the past decade, and take steps to reconcile factions there.
"The Transitional Federal Government has to tackle these issues, while earning the legitimacy to do so," the statement quoted senior ICG analyst Matt Bryden as saying.
Patchwork of fiefdoms
"If it does not, then the peace process will stall and Somalia's stubborn leaders will likely return to all-out violence," Bryden said.
Somalia has lacked an effective central government since the 1991 ouster of dictator Muhammed Siad Barre split the vast desert country of some 10 million people into a patchwork of fiefdoms controlled by regional commanders.
Two internationally recognised governments were formed before the election of Yusuf as president in October, but neither managed to establish control over the country.
The current peace process was launched in Kenya two years ago under the aegis of the regional Inter-Governmental Authority on Development, comprising Djibouti, Eritrea, Ethiopia, Kenya, Uganda, Sudan and nominally Somalia.