Mehmed IV Giray, the Sufi, was twice khan of the Crimean Khanate. His two reigns were interrupted by that of his brother Islyam II Giray. His first reign was uneventful, except for the recapture of Azov from the Cossacks. His second reign was spent fighting Russians and Cossacks in alliance with Poland. He had some reputation as a poet.
Previous khans were 1608–10: his father Selâmet I Giray, 1610: his cousin Canibek Giray, 1623: his cousin's son Mehmed III Giray, 1628: Canibek again, 1635: his cousin İnayet Giray and 1637: his brother Bahadır I Giray. For his many brothers and nephews see Selâmet I Giray#His sons. None of Mehmed's sons or grandsons became khans. In 1632–35 he was nureddin or kalga during the second reign of Canibek Giray. He then went to Ottoman territory, probably accompanying the deposed Canibek. What he did during the reigns of Inayet and Bahadir does not seem to be recorded.
First reign (1641–1644)
He came to the throne in 1641 on the death of his brother khan Bahadır I Giray. His kalga was Fetih, the brother of future khan Adil Giray. His nureddin was Gazi, the son of his brother Mubarak. Bahadir's reign had been taken up by unsuccessful attempts to drive the Don Cossacks out of Azov. In 1642 Crimean and Turkish troops forced them out, aided by pressure from the czar who did not want a Turkish war. The campaign was led by the Egyptian Pasha and accompanied by the famous traveler Evliya Çelebi. In 1645 nureddin Gazi raided the area around Kursk. Mehmed's brother Islyam complained to the Sultan that he had a better claim because he was older and had been kalga under Bahadir, but nothing was done. When the Kalmyks attacked the Kabardians Mehmed sent Salanash Mirza to their aid, but he was killed. When Mehmed came to the throne, the Kabardian chieftainship was contested by two brothers, Hakashmat beg and Antonak beg. Mehmed supported Antonak. Hakashmat fled to Azov and then to Istanbul, where the sultan declared him Prince of Circassia. The Turkish governor of Kaffa complained that Mehmed had ravaged Circassia without proper authorization, so he was deposed and replaced by his brother Islyam.
Exile under Islyam (1644–1654)
Much of Islyam's reign was taken up by the Cossack rebellion against Poland, which began in 1648 and which Crimea supported. When Islyam died of natural causes Mehmed was living at Rhodes.
Second reign (1654–1666)
He retained Gazi and Adil as kalga and nureddin. When Adil was killed by a fall from a horse, Murad became nureddin.. There was a quarrel between the Mansur and Shirin clans which seems to have been solved by Adil's death, Most of his reign involved the Polish war. In 1666 Mehmed was deposed because he had sent his son, rather than himself, to Hungary to fight the Hapsburgs and because he had attacked the 'Nogais of Bessarabia'. He retired to the Shamkhalate of Tarki where he was granted an estate and lived as a dervish. He died in 1672 and his ashes were returned to Bakhchisarai for burial. Russo-Polish War: Just before Mehmed came to the throne, Russia allied with the rebellious Cossacks, thereby provoking the Russo-Polish War. Crimea switched sides, supporting the Poles against the Russians and Cossacks. The alliance was not close and Russia tried to weaken it. Poland paid the Crimeans to invade Ukraine, which they did. A Polish-Tatar army under 'Grand-general Potocki' attacked 'Ulman' or 'Human' . Russians and Cossacks came to the rescue and were defeated at 'Drischipol'. Khmelnitski bribed the Crimeans and they withdrew, laden with booty. The Cossacks raided Poland and returning, had an inconclusive conference with Mehmed on the Oserna River. In 1657 Crimea attacked George II Rákóczi of Transylvania who was attacking Poland. The Crimeans returned with several thousand cartloads of booty. Next year Crimea sacked Rakoczi's capital of Alba Julia and returned with about 17000 slaves. In 1657 Khmelnitski died. Martyn Pushkar rebelled against the new pro-Polish hetman Vygotsky and drowned his envoys to Crimea in the Dnieper. Next year Poles and Tatars killed Pushkar and pillaged Poltava. In 1559 the Russians invaded and were defeated by Poles and Tatars at the great Battle of Konotop. In 1660 Poles and Crimeans defeated Russia at the Battle of Chudnov. Howorth claims that the Crimeans slaughtered 30000 prisoners. In 1661 the Tatars were again in Transylvania where they defeated John Kemény who had supported Rakoczi and now rebelled against the Turks. In 1663, according to Howorth, the Crimeans were fighting in Moravia and Silesia. In 1666 Mehmed was deposed.