The history of Latvia began around 9000 BC with the end of the last glacial period in northern Europe. Ancient Baltic peoples arrived in the area during the second millennium BC, and four distinct tribal realms in Latvia's territory were identifiable towards the end of the first millennium AD. Latvia's principal river Daugava, was at the head of an important trade route from the Baltic region through Russia into southern Europe and the Middle East that was used by the Vikings and later Nordic and German traders.

In the early medieval period, the region's peoples resisted Christianization and became subject to attack through the Livonian Crusade. Latvia's capital city Riga, founded in 1201 by Germans at the mouth of the Daugava, became a strategic base in a papally-sanctioned conquest of the area by the Livonian Brothers of the Sword. It was to be the first major city of the southern Baltic and, after 1282, a principal trading center in the Hanseatic League.

By the 16th century, Baltic German dominance in Terra Mariana was increasingly challenged by other powers. Because of Latvia's strategic location and prosperous trading city of Riga, its territories were a frequent focal point for conflict and conquest between at least four major powers: the State of the Teutonic Order, the Polish–Lithuanian Commonwealth, Sweden and the Russian Empire. The last period of external hegemony began in 1710, when control over Riga and parts of modern-day Latvia switched from Sweden to Russia during the Great Northern War. Under Russian control, Latvia was in the vanguard of industrialization and the abolition of serfdom, so that by the end of the 19th century, it had become one of the most developed parts of the Russian Empire. The increasing social problems and rising discontent that this brought meant that Riga also played a leading role in the 1905 Russian Revolution.

The First Latvian National Awakening began in the 1850s and continued to bear fruit after World War I when, after two years of struggle in the Latvian War of Independence, Latvia finally won sovereign independence, as recognized by Soviet Russia in 1920 and by the international community in 1921. The Constitution of Latvia was adopted in 1922. Political instability and effects of the Great Depression led to the May 15, 1934, coup d'état by Prime Minister Kārlis Ulmanis. Latvia's independence was interrupted in June–July 1940, when the country was occupied and incorporated into the Soviet Union. In 1941 it was invaded and occupied by Nazi Germany, then reconquered by the Soviets in 1944–45.

From the mid-1940s the Latvian Soviet Socialist Republic was subject to Soviet economic control and saw considerable Russification of its peoples. However, Latvian culture and infrastructures survived and, during the period of Soviet liberalization under Mikhail Gorbachev, Latvia once again took a path towards independence, eventually succeeding in August 1991 to be recognized by Russia the following month. Since then, under restored independence, Latvia has become a member of the United Nations, entered NATO and joined the European Union.

Latvia's economy suffered greatly during the Great Recession which caused the 2008 Latvian financial crisis. Worsening economic conditions and better job opportunities in Western Europe have caused a massive Latvian emigration.

Prehistory

The Ice Age in the territory of present-day Latvia ended 14,000–12,000 years ago. The first human settlers arrived here during the Paleolithic Age 11,000–12,000 years ago. They were hunters, who following the reindeer herds camped along the rivers and shore of the Baltic Ice Lake. As the geology of the Baltic Sea indicates, the coastline then reached further inland. The earliest tools found near Salaspils date to the late Paleolithic age, circa 12,000 years ago, and belong to the Swiderian culture.

During the Mesolithic Age (9000–5400 BC) permanent settlements of hunter-gatherers were established. They hunted and fished, establishing camps near rivers and lakes; 25 settlements have been found near Lake Lubāns. These people from the Kunda culture made weapons and tools from flint, antler, bone and wood.

Neolithic Age, 5000–1800 BC The early Neolithic (5400–4100 BC) was marked by the beginnings of pottery-making, animal husbandry and agriculture.

During the Middle Neolithic (4100–2900 BC) the Narva culture developed in the region. The inhabitants at this time were Finnic, forefathers of Livonians, who were closely related to Estonians and Finns and belonged to Pit–Comb Ware culture.

At the beginning of the Late Neolithic (2900–1800 BC), present-day Latvia was settled by Balts belonging to the Corded Ware culture. They were forefathers of the Latvians, and these have inhabited most of Latvian territory since the third millennium BCE.Data: 3000 BC to 1500 BC – The Ethnohistory Project

Bronze Age, 1800 BC – 500 BC

Iron Age, 500 BC–1200 AD

With the introduction of iron tools during the early Iron Age (500 BC – 1st cent. BC), agriculture was greatly improved and became the dominant economic activity. Bronze, traded from foreigners since Latvia has no copper or tin, was used for making a wide variety of decorative ornaments.

Starting from the Middle Iron Age (400–800 AD) the local inhabitants began to form distinct ethnic and regional identities. Baltic peoples eventually became the Curonians, Semigallians, Latgalians and Selonians, while Finnic peoples became the Livonians, Estonians and Vends; local chiefdoms emerged.

At the beginning of the current era, the territory known today as Latvia became famous as a trading crossroads. The renowned trade route from the Varangians to the Greeks mentioned in ancient chronicles stretched from Scandinavia through Latvian territory via Daugava to the ancient Kievan Rus' and Byzantine Empire. The ancient Balts actively participated in this trading network. Across Europe, Latvia's coast was known as a place for obtaining amber and Latvia sometimes is still called Dzintarzeme (Amberland). Up to and into the Middle Ages, amber was more valuable than gold in many places. Latvian amber was known in places as far away as Ancient Greece and the Roman Empire, and the Amber Road was intensively used for the transport of amber to the south of Europe.

During the Vendel Period a Scandinavian settlement was established near the town of Grobiņa, most likely by people from Gotland. This colony which numbered a few hundred people existed from a date between 650 and 850 AD. Many chronicles mention that Curonians paid a tribute to Swedish kings and Livonian king Danils Tkachenko.

During the Late Iron Age (800–1200 AD) the three-field system was introduced, rye cultivation began, and the quality of local craftsmanship improved with the introduction of the potter's wheel and better metal working techniques. Arab, Western European and Anglo-Saxon coins dating from this era have been found. A network of wooden hill-forts was built, which provided control and security over the land.

Early state formations

In the 10th century, the various ancient Baltic tribal chiefdoms started forming early realms. Regional tribal cultures developed in the territory of modern-day Latvia and northern Lithuania, including the Curonians, Latgalians, Selonians, Semigallians () and the Finnic Livonians, who united under their local chiefs.

The largest tribe was the Latgalians who also were the most advanced in their socio-political development. The main Latgalian principality, Jersika, was ruled by Orthodox Christian princes from the Latgalian-Polotsk branch of the Rurik dynasty. The last ruler of Jersika, mentioned in the Chronicle of Henry of Livonia (a document that describes events of the late 12th and early 13th centuries) was King Visvaldis (Vissewalde, rex de Gercike). When he divided his realm in 1211, part of the country was called "Lettia" (terra, quae Lettia dicitur), probably the first time this name is mentioned in written sources.

In contrast, the Curonians, whose territories extended into today's Lithuania and Curonian Spit, maintained a lifestyle of sea invasions that included looting and pillaging. On the west coast of the Baltic Sea they became known as the "Baltic Vikings."

Selonians and Semgallians, closely related to Aukštaitians and Samogitians, were known as prosperous farmers and resisted Germans the longest under such chiefs as Viestards. Livonians lived along the shores of the Gulf of Riga and were fishers and traders, and they gave the first German name to this territory – Livland.

Before the German invasions started in the late 12th century, Latvia was inhabited by about 135,000 Baltic people and 20,000 Livonians.

German period, 1184–1561

By the end of the 12th century, Latvia was increasingly often visited by traders from Western Europe who set out on trading journeys along Latvia's longest river, the Daugava, to Kievan Rus'. Among them were German traders who came with Christian preachers who attempted to convert the pagan Baltic and Finnic nations to the Christian faith.

In early 1180s Saint Meinhard began his mission among Daugava Livonians. They did not willingly convert to the new beliefs and practices, they particularly opposed the ritual of baptism. News of this reached Pope Celestine III in Rome, and it was decided in 1195 that Livonian Crusade would be undertaken to convert pagans by force. Meinhard was followed by Berthold of Hanover, who was killed in 1198 near the present-day Riga by Livonians.

Berthold's successor, Bishop Albert of Riga, who spent almost 30 years conquering local rulers, established the German hegemony which lasted until 20th century independence. Much of Albert's rule is described in the Livonian Chronicle of Henry. While Riga had been a trading port since ancient times, Albert is credited with its founding in 1201 when he established it as his seat of power. Riga gradually became the largest city in the southern part of the Baltic Sea.

A state known as Terra Mariana, later Livonian Confederation, was established in 1207. It consisted of various territories that belonged to the Church and Order in what is now Latvia and Estonia and was under the direct authority of the Pope of Rome. In 1228 the Livonian Confederation was established.

The Order of the Livonian Brothers of the Sword was founded in 1202 to subjugate the local population. The Livonians were conquered by 1207 and most of the Latgalians by 1214. When Brothers of the Sword were decimated at the Battle of Saule in 1236, they asked for incorporation into the Teutonic Order as the Livonian Order. In 1260, the Battle of Durbe destroyed Teuton hopes for a wide land bridge between their territories in Prussia and Courland.

By the end of the 13th century, the Curonians and Semigallians were subjugated (in 1290 the majority of Semigallians left German-conquered areas and moved to Lithuania), and the development of the separate tribal realms of the ancient Latvians came to an end as Germans introduced direct rule over subjected peoples.

In 1282, Riga (and later Cēsis, Limbaži, Koknese and Valmiera) were included in the Northern German Trading Organization, better known as the Hanseatic League (Hansa). From this time, Riga became an important point in west–east trading, and it formed closer cultural contacts with Western Europe.

Between 1297 and 1330 the Livonian Civil War raged, which started as a conflict between the Bishop of Riga and the Livonian Order.

Native people initially retained much of their personal freedoms as the number of Germans was too small to implement a total control beyond the requirements to follow Christian rites, pay the required taxes and participate as soldier in wars. In case of Curonian Kings the former tribal nobility retained a privileged status until the proclamation of independent Latvia. During the 14th century peasants had to pay 10% to the Church and work 4 days of socage per year.