In World War I, the Estonian islands were conquered by Imperial German Army in October 1917 and remained occupied (Operation Albion) until the end of hostilities. Estonia gained independence on February 24, 1918 after the October Revolution and the collapse of the Russian Empire. As a result of the Molotov–Ribbentrop Pact, the new state was incorporated into the Soviet Union in June 1940 as the Estonian Soviet Socialist Republic. Most of the Baltic German population of the island was evacuated to Germany following the Pact. The island was occupied by Nazi Germany in 1941 (Operation Beowulf); German troops remained there until expelled by the Red Army in the Moonzund Landing Operation in October and November 1944. In 1946, Saaremaa was declared a restricted zone closed to foreigners as well as most mainland Estonians. It remained a restricted area until 1989.