"Neither government forces nor our Ethiopian friends suffered any casualties in the attack, which was carried out by simple gunmen to show the international community that Mogadishu is still very unsafe," Abdirahman Dinari, a government spokesman, said.
Several people were also wounded in the brief exchange of fire.
"The Ethiopians shot me," Ali Kheyre Mumin, one of the wounded, said. "They shot at me and the others indiscriminately ... they shot everybody who was moving around."
A senior leader of the Union of Islamic Courts, which controlled Mogadishu and much of southern Somalia until December, took credit for the attack.
"This is a new uprising by the Somali people," Ahmed Qare, deputy chairman of the movement, told the Associated Press.
"The only solution can be reconciliation and talks between the transitional federal government and the Islamic courts."
The attack is the latest of several targeting Ethiopian troops who helped Somali's weak government drive fighters from the Union of Islamic Courts out of the Somali capital last month.
Meanwhile, Al Jazeera's correspondent in Nairobi has reported that 30 members of the Union of Islamic Courts and the Ogaden National Liberation Front, a group fighting for the rights of Somalis living in the Ogaden region of Ethiopia, have been arrested by Kenyan authorities.
The men are being sent to Mogadishu were they will be handed over to the Somali transitional government and the Ethiopians, he added.
Presidential compound attacked
Late on Friday, attackers fired three mortars into the presidential compound and then engaged guards in a 30-minute fire fight, residents living nearby said.
Ethiopian and government troops riding tanks and heavily armed trucks rolled out of the compound and immediately sealed off the area
There were no reports of casualties.
"Peace is possible if the interests of US and the Ethiopians are removed"
Ahmed, Bossaso, Somalia
Send us your views
The president and prime minister were in Mogadishu, but their exact whereabouts were unclear.
Dinari, the government spokesman, said one shell hit the presidential palace, known as Villa Somalia, but that no one inside was injured or killed.
"Those who ambushed the presidential palace escaped, and this is a cowardly act intended to terrorize the public," Dinari said.
The attacks have increased pressure on the Ethiopian troops to withdraw from Somalia.
The African Union has said it wants to send troops to replace the Ethiopians but it has yet to prove that it has the troops, money or logistical capability to keep the peace in Somalia.
Somalia has lacked a functioning central government since the authoritarian government of Muhammad Siad Barre was toppled in 1991.