Rákóczi's War of Independence (1703–1711) was one of the most significant attempts to topple the rule of the Habsburgs over Hungary. The war was conducted by a group of noblemen and wealthy and high-ranking progressives and was led by Francis II Rákóczi; resigned soldiers and peasants also fought alongside the noblemen. The insurrection was unsuccessful, ending with the Treaty of Szatmár, by which the Hungarian nobility managed to satisfy some important Hungarian interests. Despite the defeat, the treaty granted political and religious amnesty to the kurucs. The war of independence achieved some major political success: it prevented Hungary's full integration into the Habsburg Empire, Hungary's constitution was preserved and the power of the parliament - as the supreme legislative institution of Hungary - remained intact.
At the Treaty of Karlowitz in 1699, the Ottoman Empire renounced almost all of its claims to some of its Hungarian territories, which had been conquered from the medieval Kingdom of Hungary after 1526. The nobility was against Habsburg rule because the lands that had been taken away from them by the Ottomans were returned only to those who could both prove their right to own the properties and pay 10% of their worth to the Habsburgs. If they failed to do so, the property went to the empire's creditors. The peasants turned against the empire because of the hardships that the long wars had brought upon them. In 1697, an anti-Habsburg uprising in Tokaj was suppressed. However, relations between the court and the nobility were deteriorating, and the new Habsburg rulers treated the peasants so poorly that eventually, some people wished for a return to Ottoman rule.
International relations provided the Hungarians with an opportunity to liberate themselves from the Habsburgs. With the help of King Louis XIV of France, anti-Habsburg rebels, led by the young nobleman Imre Thököly, rose against the empire in 1678. Thököly occupied most of northern Hungary. In 1681, the Ottomans joined to help him, and he was recognised as King of Upper Hungary by Sultan Mehmed IV. However, after the Ottomans lost the Battle of Vienna in 1683, Thököly lost Ottoman support and was eventually defeated in 1685. His alliance with the Ottomans changed the positive perception that Western Europe had about Hungary, and instead of being thought of as the bastion of Christianity, the country was now being thought of as an enemy. Partly as a consequence, Hungary was occupied and organised as "newly-acquired territory" instead of "territory liberated from the Ottomans".
Francis II Rákóczi (Hungarian: II. Rákóczi Ferenc) was the son of an old noble family and one of the richest landlords in the Kingdom of Hungary. He was the count (comes perpetuus) of the Comitatus Sarossiensis (in Hungarian Sáros) from 1694 onward. He was born to Francis I Rákóczi, who was elected ruling prince of Transylvania, and Ilona Zrínyi, in 1676. His father died when Rákóczi was a mere baby, and his mother married Imre Thököly in 1682. After Thököly's defeat, Zrínyi held the castle of Munkács (today Mukacheve, Ukraine) for three years but was eventually forced to surrender. After the Treaty of Karlowitz, his stepfather and mother were sent into exile, and Rákóczi had stay in Vienna under Habsburg supervision.
Remnants of Thököly's peasant army started a new uprising in the Hegyalja region of northeastern present-day Hungary, which was part of the property of the Rákóczi family. They captured the castles of Tokaj, Sárospatak and Sátoraljaújhely and asked Rákóczi to become their leader, but he was not eager to head what appeared to be a minor peasant rebellion. He quickly returned to Vienna, where he tried his best to clear his name. Rákóczi then befriended Count Miklós Bercsényi, who was married to Krisztina Csáky and had property at Ungvár (today Ужгород (Uzhhorod), in Ukraine), lay next to Rákóczi's own. Bercsényi was a highly-educated man and the third-richest man in the kingdom (after Rákóczi and Simon Forgách) and was related to most of the Hungarian aristocracy.
As the House of Habsburg was on the verge of dying out, France was looking for allies in its fight against Austrian hegemony. Consequently, France established contact with Rákóczi and promised support if he took up the cause of Hungarian independence. An Austrian spy seized that correspondence and brought it to the attention of the emperor. As a direct result of this, Rákóczi was arrested on 18 April 1700 and imprisoned in the fortress of Wiener Neustadt, south of Vienna. It became obvious during the preliminary hearings that just as in the case of his grandfather Péter Zrínyi, the only possible sentence for Rákóczi was death. With the aid of his pregnant wife, Amelia, and the prison commander, Rákóczi managed to escape and flee to Poland. Here he met with Bercsényi again, and together they resumed contact with the French court.
Three years later, the War of the Spanish Succession caused a large part of the Austrian forces in the Kingdom of Hungary to leave the country temporarily. Taking advantage of the situation, kuruc forces began a new uprising in Munkács, and Rákóczi was asked to head it. He decided to invest his energies in a war of national liberation and accepted the request. On 15 June 1703, another group of about 3,000 armed men, led by Tamás Esze, joined him near the Polish city of Lawoczne (today Lavochne, a village in Ukraine). Bercsényi also arrived, with French funds and 600 Polish mercenaries.
Most of the Hungarian nobles did not support Rákóczi's uprising because they considered it to be no more than a jacquerie, a peasant rebellion. Rákóczi's famous call to the nobility of Szabolcs County seemed to be in vain. He, however, managed to convince the Hajdús (emancipated peasant warriors) to join his forces and so his forces controlled most of Kingdom of Hungary east and north of the Danube by late September 1703. He continued by soon conquering Transdanubia.
Since the Austrians had to fight Rákóczi on several fronts, they felt obliged to enter negotiations with him. However, the victory of Austrian and English forces against a combined French-Bavarian army at the Battle of Blenheim on 13 August 1704 not only provided an advantage during the War of the Spanish Succession but also prevented the union of Rákóczi's forces with their French-Bavarian allies.
That placed Rákóczi in a difficult military and financial situation. French support gradually diminished, and a larger army was needed to occupy the already-won land. Meanwhile, supplying the current army with arms and food was beyond his means. He tried to solve the problem by creating a new copper-based coinage, which was not easily accepted in Hungary, whose people were used to silver coins. Nevertheless, Rákóczi managed to maintain his military advantage for a while, but after 1706, his army was forced into retreat.
A meeting of the Hungarian Diet (consisting of 6 bishops, 36 aristocrats and about 1000 representatives of the lower nobility of 25 counties), held near Szécsény (Nógrád County) in September 1705, elected Rákóczi to be the "fejedelem", the (ruling) prince, of the Confederated Estates of the Kingdom of Hungary, to be assisted by a 24-member Senate. Rákóczi and the Senate were assigned joint responsibility for the conduct of foreign affairs, including peace talks.
Encouraged by England and the Netherlands, peace talks started again on 27 October 1705 between the kuruc leaders and the emperor. However, military operations continued, and both sides varied their strategy according to the military situation. On 13 December, kuruc forces, led by János Bottyán, defeated the Austrians at Szentgotthárd. One stumbling block was sovereignty over Transylvania since neither side was prepared to give it up. Rákóczi's proposed treaty with the French was stalled and so he became convinced that only a declaration of independence would make it acceptable for various powers to negotiate with him. In 1706, his wife (whom he had not seen five years, along with their sons József and György) and his sister were sent as peace ambassadors, but Rákóczi rejected their efforts on behalf of the emperor.