As the influence of the Hanseatic League waned, Riga became the object of foreign military, political, religious and economic aspirations. Riga accepted the Reformation in 1522, ending the power of the archbishops. In 1524, a venerated statue of the Virgin Mary in the Cathedral was denounced as a witch, and given a trial by water in the Daugava River. The statue floated, so it was denounced as a witch and burnt at Kubsberg. With the demise of the Livonian Order during the Livonian War, Riga for twenty years had the status of a Free Imperial City of the Holy Roman Empire before it came under the influence of the Polish–Lithuanian Commonwealth by the Treaty of Drohiczyn, which ended the war for Riga in 1581. In 1621, during the Polish–Swedish War (1621–1625), Riga and the outlying fortress of Daugavgriva came under the rule of Gustavus Adolphus, King of Sweden, who intervened in the Thirty Years’ War not only for political and economic gain but also in favour of German Lutheran Protestantism. During the Russo-Swedish War (1656–1658), Riga withstood a siege by Russian forces.
Riga remained the largest city in Sweden until 1710, a period during which the city retained a great deal of autonomous self-government. In that year, in the course of the Great Northern War, Russia under Tsar Peter the Great besieged plague-stricken Riga. Along with the other Livonian towns and gentry, Riga capitulated to Russia, but largely retained their privileges. Riga was made the capital of the Governorate of Riga (later: Livonia). Sweden’s northern dominance had ended, and Russia’s emergence as the strongest Northern power was formalised through the Treaty of Nystad in 1721. Riga became an industrialised port city of the Russian empire, in which it remained until World War I. By 1900, Riga was the third largest city in Russia after Moscow and Saint Petersburg in terms of the number of industrial workers and number of theatres.
During these many centuries of war and changes of power in the Baltic, and despite demographic changes, the Baltic Germans in Riga had maintained a dominant position. By 1867 Riga’s population was 42.9% German. Riga employed German as its official language of administration until the installation of Russian in 1891 as the official language in the Baltic provinces, as part of the policy of Russification of the non-Russian speaking territories of the Russian Empire, including Congress Poland, Finland and the Baltics, undertaken by Tsar Alexander III. More and more Latvians started moving to the city during the mid-19th century. The rise of a Latvian bourgeoisie made Riga a centre of the Latvian National Awakening with the founding of the Riga Latvian Association in 1868 and the organisation of the first national song festival in 1873. The nationalist movement of the Young Latvians was followed by the socialist New Current during the city’s rapid industrialisation, culminating in the 1905 Revolution led by the Latvian Social Democratic Workers’ Party.