defeated in a civil war (Battle of Valkininkai (Olkieniki) in November 1700) and the oligarchs appealed to Charles for protection and the removal of Augustus. 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. The majority of the Polish nobility opposed the Warsaw Confederation and considered Leszczyński's election illegal. The predominant pro-Augustus party convened the Sandomierz Confederation in May 1704 under Stanisław Denhoff as marshal, declaring their intent to defend the King and the integrity of the state and seeking the Tsardom's protection. Accordingly, the Treaty of Narva was concluded on August 30, 1704 in the recently won by the Russians Narva, with the purpose of facilitating a common front against Sweden, giving Russia the right to fight Swedish armies on the Commonwealth's territory. The Commonwealth was promised a (never realized) recovery of Livonia and the Tsardom obliged itself to help in suppressing the Cossack uprising of Semen Paliy in the right-bank Ukraine, but the treaty opened opportunities for Russia's future involvement in the affairs of the Commonwealth. The developments on the military front did not however proceed as hoped for by the pro-Saxon majority. The common Russian-Saxon-Polish offensive had failed, as Charles forced the Russians to abandon Grodno