When the war began on September 1, 1939, Latvia declared its neutrality. After the conclusion of the Molotov–Ribbentrop Pact, Latvia was compelled by a Soviet ultimatum to accept Red Army garrisons on its territory in 1939. On 16 June 1940, the Soviet Union issued an ultimatum demanding that government be replaced and that unlimited number of Soviet troops be admitted. The government acceded to the demands, and Soviet troops occupied the country on June 17. On August 5, 1940, Latvia was annexed into the USSR. The following year, USSR security agencies "Sovietized" Latvia, resulting in the deaths of between 35,000 and 50,000 residents of Latvia. The legality of the annexation was not recognised by most Western countries and the Baltic states continued to exist as formally independent nations until 1991.