In the sixteenth century, the Ottomans and the Safavids had an apocalyptic view of the conflict between them—each power was convinced that the religious truth was on its side and that the other side was indulging in heresy and had to be annihilated. Both sides wanted to claim the religious leadership of the Islamic world. Safavid Iran arose in the early sixteenth century after the fall of the Timurid Empire, which was founded by Tamerlane. Mehmed II, the conqueror of Constantinople, contributed to the rise of the Safavid dynasty by his victories over Uzun Hasan, one of the descendants of Tamerlane. With the Timurid Empire gone, the Safavids had the space to grow their empire.
The Safavids wanted Shiaism to be recognized as the fifth school of Islam, but that was not acceptable to the Sunni Ottomans. Between the sixteenth and eighteenth centuries, Ottomans and the Safavids fought several wars over religious reasons, and over the control of the South Caucasus and Mesopotamia. The Sunni-Shia divide in the Middle East today is to some extent influenced by the conflict between the Ottomans and the Safavids.
In 1514, the Ottoman Sultan Selim I issued a fatwa in the name of Sunni Islam against Shia Iran, then ruled by Shah Ismail. Selim transformed his war against Iran into a Holy War by declaring that the Safavids were heretics and must be annihilated. As he marched through the cities in Anatolia, his forces beheaded every Shiite between the age of seven and seventy. This led to the greatest massacre in Ottoman history. The forces of Shah Ismail fought bravely but Selim’s forces had the upper hand in the battle. The Safavids survived the defeat by moving their capital to Qazvin in 1555 and then from Qazvin to Isfahan in 1598—this ensured that the Safavid ruling elite was beyond the reach of the Ottoman forces. The Safavids adopted the strategy of continuous guerrilla warfare which was immensely damaging to the Ottoman economy.
In 1548, Suleiman the Magnificent launched a campaign against Iran. His army laid waste to large parts of Persia and conquered most of modern Iraq, including the city of Baghdad, the historic seat of the Abbasid caliphate, which was of religious importance to the Shi'ites. In 1555, Suleiman the Magnificent and Shah Tahmasp, the Iranian Emperor, negotiated the Treaty of Amasya to draw a border between their empires and end their conflict. But in 1577, the Ottoman sultan Murad III discarded the treaty. He was determined to destroy the Safavids. His ambition condemned the two empires for fifty years of bloodshed. Between 1578 and 1639, the Ottomans and the Safavids fought three wars. For a brief period, 1588–1629, Baghdad came under direct Safavid rule.
In 1638, Murad IV took the leadership of the Ottoman military and he captured Revan and Tabriz from the Safavids. In 1638, he captured Baghdad after a siege of forty days. On 17 May 1639, both sides signed the Treaty of Zuhab which settled the Ottoman–Persian frontier, with Iraq ceded to the Ottomans. The Safavid Empire went into decline towards the end of the seventeenth century, and the Ottomans took advantage of their problems to usurp several territories in Georgia, Iranian Azerbaijan, and Armenia. But in the eighteenth century there was the rise of Nadir Shah who deposed the last members of the Safavid dynasty and became a Shah himself. During the Ottoman–Persian War of 1730–1735, Nadir Shah forced the Ottomans to accept Persian hegemony over the Caucasus.
Weakened by the unending conflict with the Safavids and other powerful forces in the Middle East, the Ottomans could not defend their lengthy northern border in Europe which they shared with the Habsburg empire, the Polish-Lithuanian Commonwealth, and Orthodox Russia. They were doomed after the eighteenth century (perhaps from the middle of the seventeenth century). It is surprising that they continued to be a geopolitical power in the twentieth century and it took a world-historical event like the First World War to break apart their empire.