Estonia gained independence in the aftermath of World War I and Estonian War of Independence (1918–1920). In 1940 as a consequence of the German–Soviet Nonaggression Pact and its of August 1939 Estonia was occupied and annexed by the Soviet Union.