He lost both parents while still a child. He studied at the Lutheran college in Prešov at a time when anti-Habsburg rebels and Protestants were constantly in arms against the imperial troops in Slovakia. In December 1670, when his father Stephen Thököly, a participant of the anti-Habsburg Wesselenyi Conspiracy, was killed by imperial troops when protecting his Orava castle (in northern Slovakia), he fled from the castle to Transylvania, where he took refuge with his kinsman Michael Teleki, the chief minister of Michael Apafi, prince of Transylvania. Here he came into contact with refugees from historic Hungary (more exactly from present-day Slovakia), who had great hopes of the high-born, high-gifted youth who was also a fellow sufferer, a large portion of his immense estates having been confiscated by the emperor. The discontent reached its hight when the emperor Leopold I, Holy Roman Emperor (Feb. 27, 1673) suspended the Hungarian constitution, appointed Johan Caspar Ampringen dictator, deprived 450 Protestant clergy of their livings and condemned 67 more to the galleys.
Encouraged by promises of help from Louis XIV of France, the anti-Habsburg rebels now rose "pro libertate et justilia", and chose the youthful Thokoly as their leader. The war began in 1678. Eastern Slovakia and the central Slovak mining towns were soon in Thokoly's possession. In 1681, reinforced by 10,000 Transylvanians and a Turkish army under the pasha of Oradea, he compelled the emperor to grant an armistice. In June 1682 he married Helena Zrinska (Helen Zrinyi), the widow of Prince Francis Rakoczy I. Thokoly's distrust of the emperor now induced him to turn for help to the sultan, who recognized him as prince of "Upper Hungary" (i.e. eastern Slovakia and parts of northeastern present-day Hungary) on condition that he paid an annual tribute of 40,000 tallers. In the course of the same year Thokoly captured fortress after fortress from the emperor and extended his dominions to the Váh river. He refused, however, the title of king offered to him by the Turks. At the two Diets held by him, at Košice and Tállya, in 1683, the estates, though not uninfluenced by his personal charm, showed some want of confidence in him, fearing lest he might sacrifice the national independence to the Turkish alliance. They refused therefore to grant him either subsidies or a levy en masse, and he had to take what he wanted by force.
Thokoly materially assisted the Turks in the Vienna campaign of 1683, and shared the fate of the gigantic Turkish army. The Turkish grand vizier nevertheless laid the blame of the Turkish defeat in Vienna on Thokoly, who thereupon hastened to Edirne to defend himself before the Turkish sultan. Shortly afterwards, perceiving that the Turkish cause was now lost, he sought the mediation of the Polish king John III Sobieski to reconcile him with the emperor, offering to lay down his arms if the emperor would confirm the religious rights of the Protestants in Hunagary and grant him, Thokoly, Upper Hungary (more exactly: 13 north-eastern counties of historic Hungary) with the title of prince. Leopold refused these terms and demanded an unconditional surrender. Thokoly then renewed the war. But the campaign of 1685 was a series of disasters, and when he sought help from the Turks at Oradea they seized and sent him in chains to Edirne (possibly because of his previous negotiations with Leopold), whereupon most of his followers made their peace with the emperor.
In 1686 Thokoly was released from his dungeon and sent with a small army into Transylvania, but both this expedition and a similar one in 1688 ended in failure. The Turks then again grew suspicious of him and imprisoned him a second time. In 1690, however, the Turks despatched him into Transylvania a third time with 16,000 men, and in September he routed the united forces of General Heister and Michael Teleki at Zernest. After this great victory Thokoly was elected prince of Transylvania by the Keresztenymez Diet, but could only maintain his position against the imperial armies with the utmost difficulty. In 1691 he quitted Transylvania altogether. He led the Turkish cavalry at the battle of Slankamen, and in fact served valiantly but vainly against Austria during the remainder of the war, especially distinguishing himself at Zenta (1697).
He was excluded by name from the amnesty promised to the Hungarian rebels by the Treaty of Karlowitz (Jan. 26, 1699). After one more unsuccessful attempt, in 1700, to recover his principality, he settled down at Galata (near Constantinople) with his wife. From the sultan he received large estates and the title of count of Widdin.
He died in 1705 in Nicomedia.
References