Maximilian Emanuel, who had married Archduchess Maria Antonia, the sole child of Emperor Leopold's Spanish marriage, was one of the more serious claimants to the Spanish inheritance of
Charles II of Spain, and the birth of his son
Joseph Ferdinand in October 1692 immediately created a new claimant to the Spanish throne. In October 1698,
William III of England and
Louis XIV of France concluded the
First Partition Treaty, which gave the Spanish crown with the Indies to Joseph Ferdinand, the
Duchy of Milan to Emperor Leopold's younger son Archduke
Charles, and the rest of Spanish Italy to France. The unexpected death of Joseph Ferdinand four months later voided this plan and in the
Second Partition Treaty, the Bavarian portion of the inheritance was allotted to Archduke Charles. By the outbreak of the
War of the Spanish Succession in 1701, Maximilian Emanuel, who had long-term imperial aspirations, had hoped that his governorship of the Spanish Netherlands might yet reap the reward of a share of the Spanish inheritance from either Leopold or, failing him, Louis XIV. Allying himself with the French against Austria, his campaign against
Tyrol in 1703 did not have success and his plans were then frustrated by the disastrous defeat at the
Battle of Blenheim in 1704. In 1704–05, following the evacuation of the Bavarian court to the Spanish Netherlands after the defeat at the Battle of Blenheim, Max Emanuel's consort apparently was in charge of the government in the Stewardship of Munich of the Electorate of Bavaria as Regent Princess. However, when Theresa Kunegunda had found love letters of the Countess of Arco, a mistress of Max Emanuel, she left Munich to see her mother in Venice. The army would not allow her to return. In the ensuing evacuation of his court to the Netherlands, Maximilian Emanuel's family became separated and his sons were held prisoners for several years in Austria, Clemens August being brought up by
Jesuits. Bavaria was partitioned between Austria and
Johann Wilhelm, Elector Palatine. The harsh Austrian administration which managed to extract massive amounts of money and manpower from Bavaria led to
a serious peasant uprising within a year. Maximilian Emanuel was again forced to flee the Netherlands after the
Battle of Ramillies on 23 May 1706 and found refuge at the French court in
Versailles where his late sister
Maria Anna (1660–1690) had been the
Dauphine of France. In 1712, Luxemburg and
Namur were ceded to Maximilian Emanuel by his French allies, a cession that was not definitive since France was only the occupant of what was still the Spanish Netherlands. The war between France and Austria finally ended in 1714 in the
Treaty of Rastatt in which Louis XIV compelled Austria to implement the full restoration of his faithful ally Maximilian Emanuel, including the return of the Upper Palatinate. Maximilian Emanuel was to remain in possession of Luxemburg, Namur and Charleroi until he was restored. ==Final years in Bavaria==