The Battle of Vienna in 1683 is generally regarded as the Ottoman Empire’s high water mark, since it put the empire on the defensive and eventually led to the 1699 Treaty of Karlowitz, the first truly disadvantageous treaty the Ottomans ever concluded with other European powers. If you look at the 1664 Battle of Saint Gotthard, the final clash of the 1663-1664 Ottoman-Austrian War, you can see some of the seeds of that coming Ottoman defeat, as well as the many more that would follow. The Ottomans, in fact, lost at Saint Gotthard, though they’d already won the war so the battle’s outcome was somewhat irrelevant.
The Ottoman-Austrian War began, innocuously enough, with a wayward Ottoman vassal, Prince George II Rákóczi of Transylvania (d. 1660), who decided to invade Poland in 1657 without consulting with his overlords. The Ottomans, ruled by Sultan Mehmed IV (d. 1693, though he was deposed in 1687) and his Grand Vizier, Köprülü Fazıl Ahmed Pasha (d. 1676), at first simply ordered Rákóczi deposed, but when that didn’t take they opted to teach all of their vassals a lesson about going to war without permission. And so in 1660 they invaded Transylvania, killed Rákóczi, and eventually annexed the territory to the empire instead of leaving it as a semi-autonomous vassal.
The Ottomans didn’t annex Transylvania straight away, though. Initially they replaced Rákóczi with their own candidate for the throne, but the Transylvanian nobles rejected him and elected John Kemény (d. 1662) instead. Then the Ottomans returned, this time intent on annexation, and Kemény high-tailed it out of there and over to the court of Austrian Archduke, King of Hungary, and Holy Roman Emperor Leopold I (d. 1705). Leopold was dismayed at the idea of Transylvania being absorbed into the Ottoman Empire and so he agreed to back Kemény’s bid to reacquire his throne. He sent one of his top generals, Raimondo Montecuccoli (d. 1680), to Transylvania, but he didn’t send him with very much in the way of an actual army, so Montecuccoli couldn’t really do anything but inconvenience the Ottomans and watch as they completed their conquest of Transylvania. However, the Ottomans, who were looking for an excuse to start a new war with the Habsburgs anyway, deemed this intervention a sufficient justification, and everybody started preparing for war.
In mid-1663 Ahmed Köprülü led an army of perhaps as large as 150,000 men into Habsburg Hungary, and Montecuccoli, again hopelessly outnumbered (he had less than 30,000 under his command), could only watch as they captured the city of Érsekújvár (modern Nové Zámky, in Slovakia). Leopold scrambled to raise a pan-European army to reinforce his own troops, and succeeded in roughly doubling the number of men he had to send against the Ottomans. Early the following year, a contingent of Hungarian troops under Miklós Zrínyi (d. 1664) destroyed a bridge in what is now eastern Croatia that was important to the Ottoman supply lines, but the Ottomans responded that summer by besieging and capturing Zrínyi’s own castle.
The capture of his castle took Zrínyi’s men out of the fight, but the siege also gave Montecuccoli more time to prepare for the inevitable Ottoman march toward Vienna. He was able to cobble together an army somewhere between 30,000 and 40,000 men strong and meet the Ottomans at Saint Gotthard, a monastery near the point where the Ottomans crossed the Rába River. Though Leopold’s forces, having been drawn from all over the German states and France, were naturally plagued by infighting among their leaders, Montecuccoli was able to convince everybody to attempt one united charge at the Ottoman army just after it had crossed the river. Although they were heavily outnumbered, the massed charge was enough to panic the Ottomans and send them scrambling back over the river in disarray, resulting in many drowning deaths.
Saint Gotthard stopped the Ottoman push west entirely. The battle inflicted heavy casualties on Köprülü’s Janissaries, which meant he was left with a mostly conscript/part-time army that would never have survived the march to Vienna much less have been able to successfully besiege it. However, when momentum seemed to be with the Austrians, Leopold opted to call it a day rather than press his luck by, say, trying to conquer Hungary. The momentary unity that Montecuccoli had been able to instill among his forces couldn’t possibly last, and any attempt to reverse Ottoman gains would undoubtedly provoke a response from the empire that the Austrians might not be able to withstand. Moreover, Leopold had bigger fish to fry to the West—the Spanish Habsburg line was on the brink of dying out whenever the childless Charles II died, and Leopold could see that this matter of the Spanish Succession was very likely to provoke a War between the Austrian Habsburgs and Louis XIV of France. I wonder how that all shook out.
Well, anyway, as a result, in the subsequent Peace of Vasvár the Habsburgs agreed to acknowledge Ottoman possession of Transylvania and Érsekújvár and got, really, nothing in return except peace—the Ottomans agreed to pay a small tribute to the Habsburgs annually, but the Habsburgs agreed to do the same thing to the Ottomans, so it evened out. The treaty was seen as ridiculously, offensively even, lopsided by Hungarian and Croatian leaders, who were angered by Leopold’s unwillingness to press east and try to recover some of the territory the Ottomans had taken from them over the years, and in particular by the aforementioned Miklós Zrínyi, who was furious that the Habsburgs never came to the aid of his besieged castle. This led to the “Magnate Conspiracy,” an attempt by those leaders to overthrow the Habsburgs and become independent. The conspiracy never got off the ground, in part because Mehmed ratted the plot’s leaders out to Leopold after they approached the Ottomans for assistance, and in fact this allowed the Habsburgs to consolidate their control over Croatia and Hungary in its aftermath.
In hindsight, Saint Gotthard went so badly for the Ottomans that it seems to have exposed the weakening of their former military juggernaut. Had Leopold not been so preoccupied with events to the west, and had the Allied forces not been so disunited, the aftermath of the battle might have looked very different. Had Leopold allowed Montecuccoli to pursue the retreating Ottomans back east, and had Montecuccoli been able to keep his forces together, we could be talking about Vasvár the way we talk about Karlowitz.