The first citadel and royal residence of Marrakesh was the fortress and residence known as the Ksar el-Hajjar, built by the Almoravid leader Abu Bakr ibn Umar when he founded the city in 1070.[2][1] This fortress was located just north of the current Kutubiyya Mosque. The later Almoravid emir Ali ibn Yusuf (ruled 1106-1143) attached a palace to the south, on the site of what is now the mosque. Remains of these Almoravid structures have been excavated and the remains of a stone gate called Bab 'Ali, belonging to Ali's palace, are still visible today alongside the ruins of the first Kutubiyya Mosque.[1][3]