 Mahdia was a walled city located on a peninsula that projected into the Mediterranean from the coast of what is now Tunisia , then part of Ifriqiya . The Carthaginian port of Zella had once occupied the site . Mahdia was founded in 913 by Abdullah al @-@ Mahdi Billah , the first Fatimid imam , and later was the port from which the Fatimid invasion of Egypt was launched. al @-@ Mahdi built the Great Mosque of Mahdiya , the earliest Fatimid mosque , in the new city . The other buildings erected nearby at that time have since disappeared , but the monumental access gate and portico in the north of the mosque are preserved from the original structure . 
