In the 17th century, the Confederation was beset by confessional tensions. Nevertheless, the cantons of the Confederation, unlike the Three Leagues, managed to stay out of the Thirty Years’ War (1618-48). In the second half of the century, the policy of external neutrality developed from this experience. This change was associated with a new self-perception rooted in the idea of sovereignty which gradually spread after the Holy Roman Empire granted the Confederation exemption from the Imperial Chamber Court at the Peace of Westphalia in 1648. First France and later other powers interpreted this as sovereignty under international law.
However, Switzerland was by no means a haven of peace. Social and religious tensions erupted into armed conflict in the mid-17th century. In the bloody Peasant War of 1653, the peasant insurrection was defeated by the city authorities of Bern, Lucerne, Solothurn and Basel, while the first Battle of Villmergen in 1656 saw troops from Bern and Zurich beaten by the Catholic forces of central Switzerland. Many Swiss, especially those in the impoverished mountainous regions, left their overpopulated homelands to serve as mercenaries for France and later in increasing numbers for Protestant powers such as the Netherlands, England and Prussia. The wealthy Protestant cities remained popular destinations for religious refugees, such as the Huguenots who were driven out of France in 1685.