The local despotisms in the 17th century
In the 17th century the weakening of the central authority of the Ottoman government gave rise to local despotisms in the Iraqi provinces as elsewhere in the empire. A tribal dynasty, the Banu Khalid, ruled Al-Hasa as governors from the late 16th century to 1663; and in 1612 Afrasiyab, a military man of uncertain origin, purchased the governorship of Basra, which remained in his family until 1668. With the permission and even the encouragement of these autonomous governors, British, Dutch, and Portuguese merchants who were already actively involved in Red Sea trade gained a strong foothold in Basra.
An officer and faction leader of the Janissary garrison in Baghdad, Bakr Su Bashi, revolted in the early 17th century and negotiated with the Safavid Shah 'Abbas I in order to strengthen his position. In the ensuing struggle, the Ottomans managed to retain control over Mosul and Shahrizor, but central Iraq, including Baghdad, was under Safavid rule from 1623 until Sultan Murad IV drove the Iranians out again in 1638. Whereas the Safavid occupation of Baghdad had been accompanied by the destruction of some Sunnite mosques and other buildings and had resulted in death or slavery for several thousand people, mostly Sunnites, many of the city's Shi'ite inhabitants lost their lives when the Ottomans returned to Baghdad.
The Treaty of Qasr-i Shirin (also called the Treaty of Zuhab) of 1639 brought an end to 150 years of intermittent warfare between the Ottomans and Safavids and established a boundary between the two empires that remained virtually unchanged into modern times. Ottoman sovereignty had been restored in Baghdad, but the stability of central Iraq continued to be disturbed by turbulent garrison troops and by Arab and Kurdish tribal unrest. In the south, too, even though the autonomous rule of the Afrasiyab dynasty was ended in 1668, Ottoman authority was soon challenged by the powerful Muntafiq and Hawiza tribes of desert and marsh Arabs. Iranians took advantage of this disturbed state of affairs to infiltrate southern Iraq. Only after the Ottomans suffered defeat in a European war and negotiated the Treaty of Carlowitz in 1699 was the sultan able to dispatch troops to Iraq and recover Basra.
Developments in Iraq in the middle and late 17th century reflected the disordered state of affairs in Istanbul. The energetic and effective reign of Murad IV was followed by that of the incompetent Ibrahim I (1640-48), known as "Deli (The Mad) Ibrahim," who was eventually deposed and strangled and was succeeded by his six-year-old son Mehmed IV (1648-87). The protracted crisis in the capital had an unsettling effect everywhere in the empire, undoing the reforms of Murad IV and bringing political and economic chaos.