The site had long been occupied by Baltic tribes when the monk Meinhard built a monastery c.1190 among a settlement of Livs. German merchants established a community at Riga in 1158. Bishop Albert of Livonia transferred his seat there in 1201 and founded the Livonian Brothers of the Sword, or Livonian Knights, a German military religious order whose mission was to spread Christianity in the Baltic region. The knights also established a trading station at Riga.
The city, which became an archiepiscopal see in 1254 and a member of the Hanseatic League in 1282, developed into a major commercial and handicraft center. Its favorable strategic location made it an intermediary in Russian trade with Western Europe. Although it belonged to the domain of the Livonian Knights, Riga maintained a semi-independent existence under its archbishops and German merchants, and it controlled a large part of Livonia.
Riga's acceptance of the Reformation in 1522 definitively ended the power of the archbishops there. After the dissolution of the Livonian Order in 1561, Riga was briefly independent and then passed (1581) to Poland, despite attempts by Ivan IV of Russia to seize it. Polish efforts to reintroduce Catholicism made the capture of Riga in 1621 by King Gustavus II of Sweden a welcome event for the Protestant citizens. The Swedes granted self-government to the city.
Captured (1710) by Czar Peter I during the Northern War, Riga and the rest of Swedish Livonia were ceded to Russia by the Treaty of Nystadt in 1721. Having declined during the 17th cent., Riga's commercial importance revived in the 18th and particularly with the coming of the railroad in the 19th. The city became second only to St. Petersburg as Russia's leading port and was the center of Europe's timber trade.
A leading Russian industrial center from the second half of the 19th cent., Riga had the third largest number of industrial workers (after Moscow and St. Petersburg) by the 1890s. The city was a stronghold of the Russian Social Democratic party and played an important role in the Revolution of 1905. German troops occupied Riga in 1917. After World War I, the independence of Latvia was proclaimed at Riga, which became the new country's capital.
When Latvia was incorporated into the USSR in 1940, Riga was made the capital of the Latvian SSR. During World War II the city was again occupied (1941) by the Germans, from whom it was retaken (1944) by the Soviet army. The Soviet Union encouraged non-Latvian migration to the city. By 1975 less than 40% of its inhabitants were ethnically Latvian. Riga again became the capital of independent Latvia in Sept., 1991.