Under the rule of the Aghlabid dynasty, Kairouan was at its apogee, and the mosque profited from this period of stability and prosperity. In 836, Emir Ziyadat Allah I reconstructed the mosque once more: this is when the building acquired, at least in its entirety, its current appearance. At the same time, the mihrab's ribbed dome was raised on squinches. Around 862–863, Emir Abu Ibrahim enlarged the oratory, with three bays to the north, and added the cupola over the arched portico which precedes the prayer hall. In 875 Emir Ibrahim II built another three bays, thereby reducing the size of the courtyard which was further limited on the three other sides by the addition of double galleries.