In turn, victory over Sweden in the Great Northern War (1700-21) gives Russia control over Livonia. By 1795 the whole of Courland is part of Russia too. At the end of World War I, in the Treaty of Brest-Litovsk of 1918, Russia cedes Estonia, Livonia and Courland to Germany. The German minority in the region proclame both Courland and the Baltic State. Later that year the Baltic State also includes Courland and Estonia. But at the end of 1918 Livonia and Courland become independent as the Republic of Latvia and the Baltic State is dissolved. Parts of the country are by then under control of communist agitators, that form the Latvian Socialist Conciliar Republic, but they are defeated in 1919. Having obyained independent statehood the government headed by prime minister Karlis Ulmanis of the Latviešu Zemnieku Savienība (Latvian Farmers' Union, LZS) declares a democratic, parliamentary republic. Presidency is until 1928 mainly in the hands of Janis Cakste and since 1925 of Gustavs Zemgals of the liberal Demokratiskais Centrs (Democratic Center, DC). From 1930 until 1936 Albert Kviesis of the LZS is president. The premiership changes more than 15 times until 1934. Most of the time the premiership is in the hands of the LZS. Economic depression leads in the 1930s to political turmoil and in 1934 Karlis Ulmanis of the LZS becomes prime minister for the fifth time. Ulmanis dismisses the parliament, bans outspoken and left-wing political parties, and establishes an authoritarian state.
In 1940 the USSR occupies Latvia and incorporates it as an union member. It is occupied by Germany between 1941 and 1944, but soviet rule is restored in 1944.
In 1989 the Latvian supreme soviet adopts a "Declaration of Sovereignty" and amends the constitution to assert the supremacy of its laws over those of the USSR. The pro-independence Latvijas Tautas Fronte (Latvian People's Front, LTF) gains a two-thirds majority in the supreme soviet in 1990. The soviet declares its intention to restore full Latvian independence after a "transitional" period and Ivars Godmanis is chosen prime minister. In 1991 soviet forces try unsuccessfully to overthrow the legitimate Latvian authorities by occupying the central publishing house in Riga and establishing a "Committee of National Salvation" to usurp governmental functions.
In 1991 Latvia claims de facto independence in 1991 as the Republic of Latvia, which is soon internationally recognized. In the 1993 elections eight political parties pass the 5% threshold to enter parliament, but the LTF is outvoted. Largest party becomes the liberal Latvijas celš (Latvia's Way, LC), wich forms with the Latvijas Zemnieku Savienība (Latvian Farmers' Union, LZS) a center-right coalition under the prime ministers Valdis Birkavs and Maris Gailis. The 1995 brings a deeply fragmented parliament with nine parties represented and the largest party commanding only 18 of 100 seats. Attempts to form right-of-center and leftist governments fail and a broad but fractious coalition government of six of the nine parties is formed under the non-partisan prime minister Andris Skele. He is replaced in 1997 by Guntars Krasts of the Apvieniba "Tēvzemeī un Brīvībai"/LNNK (Union For Fatherland and Freedom-LNNK, TB-LNNK). In the 1998 elections 'only' six parties obyain seats in parliament. Andris Skele's newly formed Tautas Partija (People's Party, TP) garners 24 seats. Two shaky governments under Vilis Kristopans (LC) and Andris Skele (TP) quickly collaps in less than a year. In 2000 as a compromise candidate Andris Berzins (LC) becomes prime minister. His four-party coalition lasts until the elections of 2002. In these elections LC is voted out of parliament. Einar Repse's Partija Jaunais Laiks (New Era Party, JL), which runs on an anti-corruption platform, gains the most seats and Repse heads a four-party coalition government. Latvia joins the European Union in 2004.