The 1677 invasion of Ukraine got the Ottoman Empire embroiled in war with Russia. Scholarship on the 1683 siege of Vienna rarely mentions the Ukrainian campaign although it significantly weakened Ottoman military capacities and may have saved Vienna. This article examines how the Porte’s decision to invade Ukraine came about. The sultan’s grandiose imperial visions and false intelligence of Russian military strength were key factors. Easy victory was expected and the original plan to seize Hungary and Vienna was not given up. Only a catastrophic defeat by the Russians in August 1677 challenged the Porte’s strategic priorities. But Kara Mustafa did not give up his preference for a Hungarian campaign. He promised the Hungarians that the Ottoman army would join the ongoing anti-Habsburg rebellion in spring 1678. Meanwhile he allowed them to attack the Habsburgs with French and Polish support. The analysis draws on German, French, Hungarian, Ukrainian, Russian, and Polish sources; they reveal that the invasion of Ukraine was not planned in advance and greatly contested among Ottoman leaders. The Habsburgs understood the geopolitical significance of the Ukrainian campaign but could not breathe a sigh of relief before the sultan finally declared war against Russia in April 1678.