Establishment During the
Buwayhid rule of the
Abbasid Caliphate, in , a medium-sized mosque was built near Abu Hanifa's tomb, by the orders of
Samsam al-Dawla. It was said that Abu Ja'far al-Zammam built a hall inside of the mosque in 379 AH.
Under the Seljuks Later, in 459 AH / 1066 CE, the Grand Vizier of the
Seljuk Emperor Alp Arslan, Abu Saad al-Khwarizmi or al-Mustawfi, built a shrine for Abu Hanifa in the mosque, along with a white
Dome. Al-Khwarizmi also built a school near the mosque, named the Great Imam School, for teaching the
Hanafi madhab. According to
Ibn Khallikan, the school was opened on September 22, 1067, therefore, the Great Imam school is the first school in Baghdad. It took four months and a half to build the school (from January 8, 1067 to May 15, 1067).
Under the Ottoman-Safavid Wars After the invasion of Baghdad by the
Safavid dynasty in 1508, Abu Hanifa mosque and school were destroyed and abolished, due to sectarian conflicts that the Safavids had. The Ottomans
invaded Baghdad in 1534 and replaced the Shi'ite Safavid with the Sunni Ottoman rule.
Sultan Suleiman the Magnificent first visited, after invading Iraq,
Najaf and
Karbala. And then, he visited the abolished mosque of Abu Hanifa and ordered to rebuild it and recover all the damages. Along with recovering the mosque, they also added new features to it, like a minaret, a hall, a bathroom, from 50 to 140 shops and the dome that they rebuilt was a dome that was never seen like it before. They also built a square fortress around the mosque and a watchtower. The fortress was armed with 150 soldiers with different military equipment.
Under Ottoman care In 1638, the Ottomans
recaptured Baghdad, after it was
recaptured by the Safavids in 1623.
Sultan Murad IV turned to al-A'dhamiyya and particularly, Abu Hanifa mosque, because it was the shrine of the Imam of the sultan's
madhab. A luxurious dome was built on the mosque. He also brought some of the
al-Ubaid tribe to live in houses around the mosque to protect it. With the administration of
Shaykh al-Islām Yahya, the sultan ordered to rebuild the buildings around the mosque and decorate it with strips of gold and silver, decorate the mosque with green wool drapes and expand the upper and lower gates. The mosque became at its greatest during the period of the rule of Sultan Murad IV. The Sunni endowment, with the corporation of several companies and families, rebuilt the destroyed parts of the mosque, until it was fully recovered in 2004. In 2006, missiles fired by a
Katyusha rocket launcher fell into the mosque's courtyard without any damage to the mosque. == Description and architecture ==