After being abandoned during the Almohad period and falling into ruin, it was rebuilt in the 1560s by the Saadian sultan Abdallah al-Ghalib and then completely rebuilt again by the Alaouite sultan Moulay Sliman at the beginning of the 19th century, with construction of the minaret finishing in 1819 or 1820.[72] This reconstruction has eliminated all traces of the original mosque, and the current mosque is much smaller than the original and features a very different qibla orientation.[73][23] Abdallah al-Ghalib was also responsible for building the adjacent Ben Youssef Madrasa, which contained a library and operated as an educational institution up until the 20th century.