The Latvian War of Independence (5 December 1918-11 August 1920) was a war fought between the nationalist government of Latvia (backed by the Entente powers), the anti-communist and anti-nationalist Freikorps forces under Rudiger von der Goltz, and the Russian Bolshevik and Latvian communist forces. On 18 November 1918, the People's Council of Latvia proclaimed the state's independence, and the Russian SFSR responded by invading the new republic in December of that year. Much of the invading army consisted of Latvians loyal to the puppet Latvian Socialist Soviet Republic, and the Soviet invasion met little resistance at first. Riga fell to the Red Army on 3 January 1919, and the Latvian government and the German forces in the country withdrew to Liepaja. On 13 January 1919, the Latvian SSR was proclaimed.
On 18 February 1919, Latvia and Estonia formed an alliance against the Bolsheviks, and the German forces in the Baltics (including both German Freikorps volunteers and former Imperial Russian Army prisoners-of-war who were opposed to the Bolsheviks) assisted the Latvians and Estonians in recapturing much of the country from the unpopular Reds. Tukums was recaptured on 15 March, followed by Jelgava on 18 March. On 16 April 1919, the aristocratic Baltic Germans organized a coup in Liepaja, and Andrievs Niedra became the head of a Latvian puppet government. On 22 May 1919, the Freikorps captured Riga from the Reds, and, by June, Soviet rule was reduced to Latgale. After the capture of Riga, the German forces advanced north towards the Latvian city of Cesis. The Germans now sought to establish their supremacy in the Baltics by destroying the Latvian and Estonian nationalist forces instead of the communist forces. On 19 June 1919, the Baltische Landeswehr and the Freikorps launched an attack to capture Cesis from the Estonian and Latvian forces. The Estonians defeated the Germans and went on full counter-attack, forcing Alfred Fletcher's Landeswehr to withdraw to the northeast of Cesis. On the morning of 23 June, the Germans began to withdraw to Riga. The Entente powers insisted that the German forces leave the Baltics, as they had been permitted to remain in the Baltics with the sole mission of fighting against the Bolsheviks, not against the new republics. On 8 July 1919, Karlis Ulmanis' government returned to power in Riga, and the Landeswehr became a component of the Latvian military. The Freikorps, however, refused to leave the Baltics; a new West Russian Volunteer Army of 14,000 troops, 64 aircraft, 56 artillery pieces, and 156 machine guns was formed. The offensive by the reformed German army was subsequently defeated by the Latvian Army, which received assistance from British and French warships and Estonian armored trains. On 11 August 1920, the Latvian and Soviet governments made peace at Riga.