The Portuguese would subsequently attempt to occupy the city , but never managed to take it . In his journal of an expedition to the region in 1497 @-@ 1499 , the explorer João de Sá , who accompanied Vasco da Gama on the voyage , wrote that Magadoxo ( Mogadishu ) was controlled by Moors . A big town surrounded by four towers , it had houses several storeys high and large palaces in its center . De Sá and his men bombarded the city before continuing southwards along the seaboard . The Hawiye Somali , however , were later successful in defeating the Ajuran State and bringing about the end of Muzaffar rule .