The mosque of the kasbah of Tangier was thus built by Ali Errifi, under Moulay Ismail's reign in the late 17th century.[1] The mosque was expanded by Errifi's grandson, Ahmed, who added its minaret and ornate entrance.[2] Its prayer hall was expanded under Sultan Muhammad ibn Abd al-Rahman (Mohammed IV), who ruled between 1859 and 1873.[2] It was restored around 1889 for the visit of Sultan Moulay Hassan I.[2] In 1921, the official in charge of religious foundations (habous) in the region restored the mosque but covered up much of its original decoration in the process, using new colors.[2] Some of this cover-up has been cleared in recent years during renovations that finished around 2015.[3]