Germans, Poles, Swedes, and Russians competed for influence in what is now Latvia from the Middle Ages until the 18th century, when it was incorporated into the Russian Empire. During the 19th century, a Latvian nationalist movement arose which by the early 20th century sought independence. The political chaos in Europe following World War I provided the opportunity for Latvia to break away from Russia's control.
On 18 November 1918, the independent Republic of Latvia was proclaimed. Moscow recognized Latvian independence in the August 1920 Soviet-Latvian treaty, and the new republic joined the League of Nations in 1922. Latvia prospered economically during the 1920s, and began to export dairy and grain products to Europe. During the 1930s, as tensions in Europe escalated, the Soviet government allied itself with the UK and France, which in July 1939 granted the concession that Soviet troops could move into the Baltic States in case an indirect aggression was made by Germany. Sensing that an alliance between the UK, France, and the USSR would leave Germany politically and militarily surrounded, the Nazi government decided to reach its own agreement with the Soviet government in August 1939. A secret protocol to the 1939 Nazi-Soviet pact assigned Latvia to the Soviet sphere of influence.
Soviet forces invaded Latvia on 17 June 1940, and Latvia was incorporated into the USSR. Thousands of Latvia's military and law enforcement officials were executed; political and social leaders were imprisoned. Latvian civilians were deported en masse to Soviet camps in Siberia; 15,000 alone were expelled on the night of 14 June 1941. The Soviets, however, lost control of Latvia to the Germans in July 1941, shortly after Hitler launched his attack on the USSR. Soviet forces recaptured Latvia in 1944. During the Teheran Conference of November/December 1943 between US president Franklin D. Roosevelt and the Soviet leader Joseph Stalin, it was agreed that the USSR would maintain control of the Baltic States, and this agreement was confirmed at the Conference of Yalta in February 1945.
Following World War II, forced collectivization of agriculture began another round of deportations in 1949, bringing the total number of post-war deportees to more than 200,000. The Soviet policy of Russification sought to replace Latvian language and culture with those of Russia. Freedom of speech, press, and religion was denied. For most of the 50 years of Soviet rule, political dissent was strictly forbidden.
Soviet president Mikhail Gorbachev's policy of glasnost and perestroika allowed Latvians to voice their long-suppressed desire for national self-determination. In June 1987, an openly anti-Soviet demonstration took place in Riga. In 1988, political activists founded the Latvian National Independence Movement and the Latvian Popular Front (LPF). On 23 August 1989, Latvians, Lithuanians, and Estonians organized a massive demonstration of Baltic solidarity. The LPF united independence forces and gained a majority in the elections for the Latvian Supreme Council in the spring of 1990. On 4 May 1990 provisional independence and a period of transitional rule were proclaimed.
On 21 August 1991—shortly after the failure of a coup against Gorbachev—Latvia proclaimed its full independence. The first post-independence elections for the new Saeima (parliament) were held on 5–6 June 1993. On 30 April 1994, the Latvian and Russian governments signed a series of accords calling for the withdrawal of nearly all Russian armed forces from Latvia by the end of that year. On 12 June 1995, Latvia, Estonia, and Lithuania signed accords with the EU that it was hoped would eventually lead to full membership. A second parliamentary election the same year resulted in a legislature that was strongly divided between pro-Western and pro-Russian contingents. At the end of 1995, Andris Shkele, a former government official and businessman, became prime minister, heading a broad-based coalition cabinet. Shkele, who retained his post until 1997, balanced the budget and sped up economic reform although his leadership style alienated many other politicians.
The Russian economic decline of 1998 decreased the market for Latvian goods and services, seriously hurting its economy and increasing unemployment. In October of the same year, Shkele's People's Party won a plurality of the vote in new parliamentary elections, but the former prime minister's personal unpopularity resulted in the formation of a minority government by a coalition that opted to exclude him. Latvia elected its first female president in June 1999, when Vaira Vike-Freiberga, a Canadian psychology professor of Latvian birth known for promoting Latvian cultural interests internationally, was chosen as her homeland's new head of state. She was inaugurated on 8 July 1999. One of her first acts as president was to veto new legislation that would have required the use of the Latvian language in government and business communications, thus further disenfranchising Latvia's large Russian-speaking minority, whose rights and status remained a problematical issue for the country as the new century began. In May 2002, Latvia changed its election law to omit a clause requiring parliamentary candidates to be speakers of the Latvian language, a provision seen as discriminatory to Russian speakers. The change was seen to improve Latvia's chances for membership in the North Atlantic Treaty Organization.
In November 2002, NATO formally invited Latvia, along with six other countries, to become a member of the body in 2004. That December, Latvia also received an invitation from the European Union (EU) to join, with accession planned for 2004 as well. Latvia planned to hold a referendum on EU membership on 20 September 2003.
General elections were held on 5 October 2002, and a new party, the centrist New Era, topped the polls with 23.9% of the votes, taking 26 of the 100 seats in the Saeima. New Era is led by Einars Repse, the former head of the central bank, who managed the country's economy through difficult post-Soviet years; he oversaw the replacement of the currency, from the Russian ruble to the lat, an event that was seen as heralding Latvia's economic revival. Repse was named prime minister, heading a center-right coalition government formed by New Era, Latvia's First Party, the Alliance of Greens and Farmers, and the For Fatherland and Freedom Party. The For Human Rights in a United Latvia party came in second with 18.9% of the vote and 24 seats. Twenty parties competed for seats in parliament in the election. Repse, who campaigned for lower taxes, a pared-down government, and the elimination of corruption, launched a new office in 2003, an "Anti-Absurdity" bureau. Dedicated to help ordinary people fight "the arbitrariness of those in power, the laziness of civil servants, and the lack of order in national and local government," it is a sounding board for a variety of public complaints.
Both Repse and President Vike-Freiberga supported the 2003 US-led military campaign against Saddam Hussein's regime in Iraq. Vike-Freiberga emphasized the need to maintain the trans-Atlantic relationship guaranteeing Latvia's security, and the country's opposition to the rule of dictators who challenge the international community.