The mosque was founded by the Alaouite sultan Moulay Mohammed ben Abdallah (who briefly made Rabat his royal capital) and was completed in 1785.[2][3][4] However, it was almost entirely restored in the 19th century.[2] In 1969, on the occasion of King Hassan II's 40th birthday, the mosque was renovated again and its minaret was moved from its original position at the northwest corner of the mosque and reconstructed "stone by stone" at the mosque's southwest corner, where it stands today, in order to enhance its perspective along the axis of Avenue Mohammed V.[5][6][7]