Ahmad al-Mansur
The Saadians further embellished the mosque by adding two prominent pavilions to the western and eastern ends of the courtyard, each of which sheltered a new fountain. The famous Saadian sultan Ahmad al-Mansur was responsible for building the first pavilion to the east in 1587–88, while the western pavilion was added under his grandson Abdallah al-Ghalib II in 1609. The pavilions emulate those found in the Court of Lions of the Alhambra palaces (in Granada, Spain). This was the last major addition to the mosque's architecture. The Saadian sultan Ahmad al-Mansur also built a new room for the library on the south side of the mosque (around the library's current location), which was connected to the mosque via a door in the qibla wall.