In the 17th century, the city was governed by the wealthy al-Naksis family. At the end of the century, the city was taken by the Alaouite sultan Moulay Ismail who encountered fierce resistance. Tetouan remained fragile, until it was taken by Ahmad al-Riffi, the Alaouite governor of Tangier and leader of the Berber army Jaysh al-Rifi that had conquered Tangier from the British. Al-Riffi ushered in a period of stability in Tetouan, building many of Tetouan's landmarks such as the Meshwar palace and the Pasha mosque, the oldest still standing mosque in Tetouan. After his death, the city again rebelled and was only nominally controlled by the central government.
