A conflict that arose on the death of the childless Charles II of Spain in 1700. One of his sisters had married Louis XIV, the other Emperor Leopold, so both the French Bourbons and the Austrian Habsburgs claimed the right to rule the Spanish empire, which included the southern Netherlands, Milan, Naples, and most of Central and South America. Before Charles II's death William III took a leading part in negotiations to pre-empt the crisis, and a partition treaty was signed (1698) between Louis XIV and William, that Spain and its possessions would be shared out between France, Austria, and Joseph Ferdinand, the 7-year old Elector of Bavaria, grandson of Leopold. Charles II meanwhile left all of Spain's empire to Joseph Ferdinand. When he died, Louis and William signed a second partition (1699). However, Charles II left a will bequeathing his whole empire to Louis XIV's second grandson, the future Philip V. Louis accepted this will and, instead of allaying European fears of French domination, intervened in Spanish affairs, seized the Dutch barrier fortresses, recognized James II's son as King of England, and refused to make it impossible for Philip also to inherit the French throne.
In 1701 William III formed a grand alliance of the English and Dutch with the Austrian emperor and most of the German princes to put the rival Austrian candidate, the Archduke Charles, on the throne; Savoy and Portugal later joined the alliance. William died in 1702 and the war therefore became Queen Anne's War. Fighting took place in the Netherlands, Italy, Germany, and Spain. France's only allies were Bavaria and the people of Castile, who supported Philip V while Catalonia declared for the Archduke Charles. Marlborough and Eugène of Savoy won a series of brilliant victories, including Blenheim. France was invaded in 1709 and the allies were stronger at sea, taking Gibraltar, in 1704. The war came to an end because Castile would not abandon Philip V and when Marlborough fell from power the new Tory government in England began the negotiations, which led to the Peace of Utrecht (1713).