Government troops battled gunmen who attacked the Somali president's palace in central Mogadishu Friday night, spreading panic around the capital.

The attackers fired three mortars into the presidential compound and then engaged guards in a 30-minute firefight, residents said. The president and prime minister were in Mogadishu, but their whereabouts were unclear and government officials did not immediately answer their phones.

Khadra Dahir Osman, who lives next to the presidential compound, which occupies a hill overlooking Mogadishu, said he fled to his brother's home, panic-stricken.

The internationally recognized government — with key military backing from Ethiopia — had managed to drive an Islamic movement that had challenged it for power out of Mogadishu and much of the rest of southern Somalia. But the potential for violence remains great because of clan rivalries, resentment of the government's Ethiopian backers and a threat of guerrilla war from remnants of the Islamic movement.

Prime Minister Ali Mohamed Gedi arrived in Mogadishu Dec. 29, a day after the Islamic movement's fighters abandoned the capital. President Abdullahi Yusuf arrived Jan. 8. Since then, their government has struggled to restore order to a capital that has known little but chaos and violence for decades.