Tin Mal is counted as being among the most important historical sites of Morocco. Here is found the spiritual home of Ibn Toumert, who came to be the founder of the Almohad dynasty in the 12th century.
Tin Mal was founded in 1125, after Ibn Toumert was driven out of Marrakech by the Almoravids. By the time he died 5 years later, he had started a siege of Marrakech, but the city didn't give in until 1147. When that happened Tin Mal lost its strategical importance.
Its role as an important religious centre continued, and when it was time for the Merenids to take control over Morocco a good century later, Tin Mal became the last stronghold for the Almohads.
The mosque itself was erected around 1153/4, and had fortification walls added to it, in order to serve as protection in case of attack.