Before World War I began Europe had between divided into two major alliances, the Triple Alliance and the Triple Entente, which became the Central powers and the Allied powers during the war. (Source: ericsworldwarone.weebly.com)
When the first World War began Latvia, like the rest of the Russian Empire, prepared by mobilizing, with 20000-25000 Latvian soldiers sent to the Eastern Front at the beginning of the war. Thousands of these soldiers were killed when the Germans defeated the Russian army at the battle of Masurian Lakes in early 1915. By the spring the German army had entered Latvia in their counterattack against Russia, and Latvian Home Guards fought against them alongside the Russian army. By the fall of 1915 the Germans controlled half of Latvia, so several Latvians asked the Russian Command if they could create 100% Latvian units to protect their homeland. While many of the Russian commanders didn’t like this idea, as they thought it would cause more Nationalism in Latvia, Tsar Nicholas approved it. Within two days more than 6000 men had volunteered for these all-Latvian units, who were called the Latvian Riflemen.
Latvian Riflemen (Source: latvianhistory.com)
In late fall they stopped the German army from moving forward, and the war in Latvia remained in a stalemate for the next two years. The Latvian Riflemen were also part of a Russian attack that the Tsar had been pressured into doing by the Western allies, as things were not going well for them on the Western Front. This attack was a failure and both the Russians and the Latvians serving under them suffered heavy losses. The fighting continued like this until 1917, when the collapse of the Russian government and the abdication of the Tsar meant the Russian Imperial troops abandoned Riga and retreated as the Germans advanced. Because of this abandonment radicals took control of the Latvian Riflemen, and many of them joined the Bolsheviks, the communist revolutionaries led by Vladimir Lenin, while others fought for a independent Latvia.
Vladimir Lenin, the Bolshevik leader, leading 1917 Russian Revolution (Source: Encyclopedia Britannica)
Despite the German victory on the Eastern front they were defeated in the west and were forced to sign an armistice with the remaining allies. One week after Germany signed the armistice, on November 18th, 1918, Latvia declared independence. Because the Latvian Riflemen, who numbered at almost 24000, had already taken over large parts of the country for the Bolsheviks who were fighting a civil war against the Tsarists (pro-Tsar fighters) in Russia, the new Latvian government had to create a new army from scratch. Other problems for Latvia came in the form of the Russian White Army, the combined forces of the Tsarists and supporters of the Interim government the Bolsheviks had overthrown, and the remnants of the German army, who the Allies had asked to protect the region against the Bolsheviks, but had tried to take control of the region for themselves. British ships and soldiers also became involved in the conflict, as well as the in the Russian Civil War. After two years of heavy fighting Latvia and the USSR signed a peace treaty on August 11th, 1920. Estonia and Lithuania also made peace with the Soviet Union around the same time.
The Latvian leaders declare independence on November 18th, 1918 (Source: latvianhistory.com)