A Somali source said that Abdullahi Yusuf, the president, was inside the building at the time of the attack.
After the mortar attacks, fighters with machineguns ran towards the building where they fought presidential guards around the hilltop compound for about 20 minutes before retreating, witnesses said.
Yusuf recently took up residence in the palace which had been used by Mohamed Siad Barre, Somalia's former dictator, prior to his ouster in 1991.
Fighters from the Islamic Courts Union, which was only recently driven southwards from Mogadishu by Somali government and Ethiopian troops, are thought to be behind the attack.
One former Islamic court's soldier said: "Many Islamists have started infiltrating Mogadishu again."
He said that an attack on the Villa Somalia had been planned.
A Somali government bodyguard reached by telephone said the attack was launched from a school just a few blocks north of the white-washed presidential compound.
Ethiopian troops, who backed the Somali interim government forces as they claimed Mogadishu, have often been the target of attacks.
Ethiopia is keen to withdraw its troops quickly.
Meles Zenawi, the Ethiopian prime minister, has said his forces would start leaving "in the next few days".
"Peace is possible if the interests of US and the Ethiopians are removed"
Ahmed, Bossaso, Somalia
Send us your views
In Addis Ababa, the Ethiopian capital, the African Union's key Peace and Security Council approved sending a peacekeeping mission to Somalia for six months, after which it hopes to give way to a UN mission.
The council authorised the depoyment of a peackeeping force of more than 7,600, agreeing to send nine battalions of 850 troops each with immediate effect, a statement released after the meeting said.
The initial deployment will be one-third that number.
The African Mission to Somalia, or Amisom, is to "facilitate humanitarian operations in Somalia and consolidate peace and stability in Somalia", the statement said.
Diplomats say international peacekeepers will be the only way to stabilise Somalia following the departure of Ethiopian troops.