 The Great Mosque of Mahdiya was built in Mahdia , Tunisia , in 916 CE ( 303 – 304 in the Islamic calendar ) , on an artificial platform " reclaimed from the sea " as mentioned by the Andalusian geographer Al @-@ Bakri , after the founding of the city in 909 by the first Fatimid imam , Abdullah al @-@ Mahdi Billah . Internally , the Great Mosque had a layout similar to other mosques in the region . A transverse aisle paralleled the qibla wall , with nine aisles at right angles to the transverse . The original qibla wall was destroyed by sea erosion and had to be rebuilt , reducing the size of the prayer hall . Like other mosques in the region , the orientation of the qibla differs significantly from the " true " great circle route to Mecca . 
