Charles defeated the Saxon army at a battle near Riga in 1701, took over Courland and entered the Commonwealth, at that time not an official participant of the war. The Swedes took Warsaw and moved toward Kraków, which also fell as the Saxon and Polish forces were beaten at Kliszów in July 1702. Further Saxon defeats took place the following year at Pułtusk and Thorn (Toruń), which split the Commonwealth nobility and intensified the anti-Saxon opposition led by Cardinal Radziejowski. A confederation in Warsaw, based mainly on Greater Poland nobility, was convened, and, following the wishes of Charles XII, proclaimed a dethronement of Augustus on Feb. 14, 1704. On July 12, the election as king of Stanisław Leszczyński, the Voivode of Poznań, took place. It was the first free election in which the outcome was imposed by a foreign ruler, and the chosen, young and well-educated Polish magnate, was completely subservient to Charles. Stanisław's elevation was followed by a country-wide civil war and by the Treaty of Warsaw (1705), aimed at subjugating the Commonwealth to Swedish dominance. The Swedish monarch was granted permanent extensive territorial and other concessions, such as the right to station and conscript troops, and intended to use the Commonwealth's resources to fight Russia, his main adversary.