Abdirahman Dinari, the government's spokesman, said: "The warlords and the government have agreed to collaborate for the restoration of peace in Somalia."
Yusuf had met three prominent local commanders and two other faction leaders, the spokesman said. "The agreement means they have to disarm their militia and their men have to join the national army."
An Associated Press reporter at the scene counted six dead bodies, and was told that one other person was killed.
Ten others were wounded. The firefight involved troops loyal to clan leader Mohamed Qanyare Afrah and those loyal to the president, who belongs to a rival clan.
"Somalia supports the goverment's vision and its values"
Liban, Galkio, Somalia
Send us your views
Qanyare and other clan leaders were meeting with President Yusuf inside the building when the fighting started. Mohammed Said Dore, a witness in the area, said: "Gunmen have fired one rocket-propelled grenade at one of the entrances of the presidential palace in villa Somalia.
"The people in the area have fled. Then security forces and Ethiopian troops manning the site exchanged fire with gunmen for around ten minutes. After that the gunmen fled."
Ali Mohammed, a member of the presidential guard, said all the dead were from Qanyare's loyalists and that 10 others had been arrested.
He accused the fighters of trying to force their way into the presidential compound. Abdiqadir Hussien Hassan, a government official who works inside the compound, said it was not clear what triggered the fighting.
But Qanyare has long controlled much of Mogadishu with his clan fighters and he has competed with Yusuf in the past.
Meanwhile, the Washington Post has reported that a small US military team visited the site of Monday's US air strike in southern Somalia to try to determine the identity of those killed.
The visit is the first reported case of US soldiers on the ground in Somalia since the 1994 mission that killed 18 US soldiers in Mogadishu and was immortalised in the film "Black Hawk Down".
|A US gunship attacked a suspected al-Qaeda|
base in southern Somalia on Monday [EPA]
It was not known if the team was still in Somalia, the Post reported.
A US official told AFP on Thursday in Nairobi that the Monday air strike killed "eight to 10" alleged al-Qaeda affiliates, but none of the three top fighters sought by the US in the violence-wracked nation.
According to the Post, a piece of bloody clothing and a document found at the site suggested that Aden Ayrow, head of the military arm of the Union of Islamic Courts, had been at the scene.
The Pentagon has said the operation was prompted by "credible intelligence" that the "principal al-Qaeda leadership" in east Africa was in the area that was hit by an AC-130 gunship, a fixed-wing aircraft with rapid firing guns.