The Qaraouiyine mosque was built in 857 in the Qaraouiyine neighbourhood where refugees from Kairouan, Tunisia, used to live. They settled on that bank of the Oued Fez in the 9th century. Built under the reign of the Idrissides by Fatima Al Fihria, daughter of a wealthy Kairouan merchant in 933, it became the main mosque in the city.