Which led most directly to Spain losing control of the Netherlands?

The War of Spanish succession led most directly to Spain losing control of the Netherlands. This was a war between European powers on who to succeeded Charles II.