The Great Northern War (1700–1721) was a conflict in which a coalition led by the Tsardom of Russia successfully contested the supremacy of the Swedish Empire in Central, Northern, and Eastern Europe. The initial leaders of the anti-Swedish alliance were Peter the Great of Russia, Frederick IV of Denmark–Norway and Augustus II the Strong of Saxony-Poland-Lithuania. Frederick IV and Augustus II were forced out of the alliance in 1700 and 1706 respectively, but rejoined it in 1709. George I of Brunswick-Lüneburg (Hanover) joined the coalition in 1714 for Hanover and in 1717 for Britain, and Frederick William I of Brandenburg-Prussia joined it in 1715.
Charles XII led the Swedish army. On the Swedish side were Holstein-Gottorp, several Polish and Lithuanian magnates under Stanislaw Leszczynski (1704–10) and Cossacks under the Ukrainian Hetman Ivan Mazepa (1708–10). The Ottoman Empire temporarily hosted Charles XII of Sweden and intervened against Peter I.
The war started when an alliance of Denmark–Norway, Saxony and Russia declared war on the Swedish Empire, launching a threefold attack at Swedish Holstein-Gottorp, Swedish Livonia, and Swedish Ingria, sensing an opportunity as Sweden was ruled by the young Charles XII, who was eighteen years old and inexperienced. Sweden parried the Danish and Russian attacks at Travendal and Narva, and in a counter-offensive pushed August II's forces through Lithuania and Poland to Saxony, dethroning Augustus on the way and forcing him to acknowledge defeat in the Treaty of Altranstädt. The treaty also secured the extradition and execution of Johann Reinhold Patkul, architect of the alliance seven years earlier. Peter I had meanwhile recovered and gained ground in Sweden's Baltic provinces, where he cemented Russia's access to the Baltic Sea by founding Saint Petersburg in 1703. Charles XII moved from Saxony into Russia to confront Peter, but the campaign ended with the destruction of the main Swedish army at the decisive 1709 Battle of Poltava (in present-day Ukraine), and Charles' exile in Ottoman Bender. The Ottoman Empire defeated the Russian-Moldavian army in the Pruth River Campaign, but the peace treaty was in the end without great consequence to Russia's position.
After Poltava, the anti-Swedish coalition was re-established and subsequently joined by Hanover and Prussia. The remaining Swedish forces in plague-stricken areas south and east of the Baltic Sea were evicted, with the last city, Riga, falling in 1710. Most of the Swedish dominions were partitioned among the coalition members, destroying the Swedish dominium maris baltici. Sweden proper was invaded from the west by Denmark–Norway and from the east by Russia, which had occupied Finland by 1714. The Danish forces were defeated. Charles XII opened up a Norwegian front, but was killed in Fredriksten in 1718. Some people think that one of his own men killed him because the Swedish simply couldn't afford to fight anymore wars.
The war ended with Sweden's defeat, leaving Russia as the new dominant power in the Baltic region and arguably a major force in European politics. The formal conclusion of the war was marked by the Swedish-Hanoverian and Swedish-Prussian Treaties of Stockholm (1719), the Dano-Swedish Treaty of Frederiksborg (1720), and the Russo-Swedish Treaty of Nystad (1721). Therein, Sweden ceded her exemption from the Sound Dues, and lost the Baltic provinces and the southern part of Swedish Pomerania. The peace treaties also ended her alliance with Holstein-Gottorp. Hanover gained Bremen-Verden, Brandenburg-Prussia incorporated the Oder estuary (Stettin Lagoons), Russia secured the Baltic provinces, and Denmark strengthened her position in Schleswig-Holstein. In Sweden, the absolute monarchy had come to an end with the death of Charles XII, and the Age of Liberty began.