In 1940, in the wake of the Molotov–Ribbentrop Pact of 1939, the Soviet Union occupied Estonia and (according to e.g. the US, the EU, and the European Court of Human Rights) illegally annexed the country. In the course of Operation Barbarossa, Nazi Germany occupied Estonia in 1941; later in World War II the Soviet Union reoccupied it (1944). Estonia regained independence in 1991 in the course of the dissolution of the Soviet Union and joined the European Union and NATO in 2004.