At the outset of World War II in September 1939, Denmark declared itself neutral, but that neutrality did not prevent Nazi Germany from occupying the country soon after the outbreak of war; the occupation lasted until Germany's defeat. The decision to occupy Denmark was taken in Berlin on 17 December 1939. On 9 April 1940, Germany invaded Denmark in Operation Weserübung. In contrast to the situation in other countries under German occupation, most Danish institutions continued to function relatively normally until 1945. Both the Danish government and King of Denmark remained in the country in an uneasy coalition between a democratic system and a totalitarian one until, amidst growing civilian resistance and unrest, the Danish government refused to further cooperate with the Germans' demands; in response, on 29 August 1943, Germany declared martial law and placed Denmark under direct military occupation, which lasted until the Allied victory on 5 May 1945.

The German occupation of Denmark formed part of Berlin's broader strategic plans in northern Europe. Denmark occupied an important geographic position as the gateway to the Baltic Sea and as a transit route between Germany and occupied Norway. Control of Danish airfields and ports enabled German forces to support naval and air operations in the North Sea and the North Atlantic. The occupation was also intended to secure agricultural production and maintain stable deliveries of food products to Germany during wartime shortages.

During the first years of occupation, the Danish policy of cooperation () was defended by politicians as a means of preserving a degree of national autonomy and protecting the population from harsher German measures. The Danish parliament, courts, police and civil administration continued to operate, although under increasing German pressure and censorship. The arrangement became controversial both during and after the war, as critics argued that cooperation indirectly assisted the German occupation authorities.

Just over 3,105 Danes died as a direct result of the occupation. A further 2,000 volunteers of Free Corps Denmark and Waffen-SS, most of whom originated from the German minority of southern Denmark, died fighting on the Eastern Front, while 1,072 merchant sailors died in Allied service. Overall, this represents a very low mortality rate compared to other occupied countries and most belligerent countries. In addition to the volunteers of Free Corps Denmark and Waffen-SS, some Danes chose to collaborate during the occupation by joining the National Socialist Workers' Party of Denmark, Schalburg Corps, HIPO Corps and Peter Group (often with considerable overlap between the participants of the different groups). The National Socialist Workers' Party of Denmark participated in the 1943 Danish Folketing election, but despite significant support from Germany it only received 2.1% of the votes. In Denmark, the occupation period is known as (Danish for "the Occupation").

Economic conditions in occupied Denmark differed from those in many other German-occupied territories. Danish industry and agriculture continued production throughout much of the war, partly due to trade agreements with Germany and the comparatively limited destruction within the country. Rationing of consumer goods, fuel and raw materials nevertheless affected daily life, and shortages became increasingly severe after 1943. A black market developed in major urban areas, particularly in Copenhagen, where ration coupons and scarce imported goods were traded illegally.

A resistance movement developed over the course of the war, and the vast majority of Danish Jews were rescued and sent to neutral Sweden in 1943 when German authorities ordered their internment as part of the Holocaust. The rescue operation, carried out with assistance from fishermen, resistance members and ordinary civilians, transported approximately 7,000 Danish Jews and several hundred Jewish refugees across the Øresund to Sweden during October 1943. The episode has frequently been cited as an example of widespread civilian solidarity during the Holocaust in occupied Europe.

Acts of sabotage increased significantly after 1942, particularly against railway infrastructure, factories and shipyards used by the German war effort. Resistance groups such as Holger Danske and BOPA carried out attacks in cooperation with the British Special Operations Executive (SOE), which supplied weapons and training to Danish operatives. In response, German authorities and Danish collaborators conducted reprisals, arrests and executions of suspected resistance members.

Following Germany's surrender in May 1945, Denmark was liberated by British forces under Field Marshal Bernard Montgomery. The island of Bornholm remained under Soviet occupation until April 1946 after Soviet forces bombarded and captured the island from retreating German troops. After the war, Denmark prosecuted collaborators in a series of legal proceedings known as the ("legal purge"), during which thousands of individuals were investigated or sentenced for collaboration, treason or war crimes.

Invasion

The occupation of Denmark was initially not an important objective for the German government. The decision to occupy its small northern neighbour was made to facilitate a planned invasion of the strategically more important Norway, and as a precaution against the expected Allied response. German military planners believed that a base in the northern part of Jutland, specifically the airfield of Aalborg, would be essential to operations in Norway, and they began planning the occupation of parts of Denmark. However, as late as February 1940 no firm decision to occupy Denmark had been made.Henrik Dethlefsen, "Denmark and the German Occupation: Cooperation, Negotiation, or Collaboration," Scandinavian Journal of History. 15:3 (1990), pp. 193, 201–202. The issue was finally settled when Adolf Hitler personally crossed out the words ("the Northern tip of Jutland") and replaced them with , a German abbreviation for Denmark.

Although the Danish territory of South Jutland was home to a significant German minority, and the province had been regained from Germany as a result of a plebiscite resulting from the Versailles Treaty, Germany was in no apparent hurry to reclaim it. In a much more vague and longer-term way, some Nazis hoped to incorporate Denmark into a greater "Nordic Union" at some stage, but these plans never materialized. Officially, Germany claimed to be protecting Denmark from Anglo-French attacks.Jørgen Hæstrup, Secret Alliance: A Study of the Danish Resistance Movement 1940–45. Odense, 1976. p. 9.

At 4:15 on the morning of 9 April 1940, German forces crossed the border into neutral Denmark. In a coordinated operation, German ships began disembarking troops at the docks in Copenhagen. Although outnumbered and poorly equipped, Danish soldiers in several parts of the country put up resistance, most notably the Royal Guard in Copenhagen and units in South Jutland. As the invasion began, German planes dropped the notorious leaflets over Copenhagen calling on Danes to accept the German occupation peacefully, and claiming that Germany had occupied Denmark in order to protect it against Anglo-French attacks. Colonel Lunding from the Royal Danish Army's intelligence office later confirmed that Danish intelligence knew the attack would be coming on either 8 or 9 April and had warned the government accordingly. The Danish ambassador to Germany, Herluf Zahle, issued a similar warning which was also ignored.

As a result of the rapid turn of events, the Danish government did not have enough time to officially declare war on Germany. Denmark was in an untenable position in any event, however. Its territory and population were too small to hold out against Germany for any sustained period. Its flat land would have resulted in it being easily overrun by German panzers; Jutland, for instance, was immediately adjacent to Schleswig-Holstein to the south and was thus wide open to a panzer attack from there. Unlike Norway, Denmark had no mountain ranges from which drawn-out resistance could be conducted.William Shirer, The Rise and Fall of the Third Reich (New York: Simon & Schuster, 1990), p. 663.

Sixteen Danish soldiers died in the invasion, but after less than six hours the Danish government surrendered, believing that resistance was futile and hoping to work out an advantageous agreement with Germany. Not only was the flat Jutland territory a perfect area for the German army to operate in, the surprise attack on Copenhagen had made any attempt to defend Zealand impossible. The Germans had also been quick to establish control over the bridge across the Little Belt, thus gaining access to the island of Funen. Believing that further resistance would only result in the futile loss of more Danish lives, the Danish cabinet ultimately decided to bow to the German pressure "under protest". The German forces were technologically sophisticated and numerous; the Danish forces comparatively tiny and using obsolete equipment; partially a result of a pre-war policy of trying to avoid antagonizing Germany by not supplying the army with modern equipment. Even stiff resistance from the Danes would not have lasted long. Questions have been raised around the apparent fact that the German forces did not seem to expect any resistance, invading with unarmored ships and vehicles.

Other territories within the Kingdom of Denmark

Faroe Islands

After the occupation of Denmark, British forces from 12 April 1940 made a pre-emptive bloodless invasion of the Faroe Islands to prevent their occupation by German troops. Britain took over the areas where Denmark previously had given support, and the islands now became dependent on the United Kingdom, which began to participate in fishing production and supplied the islands with important goods.

The British fortified positions in strategically important locations in the Faroe Islands. Sounds and fjords were mined, and at the island of Vágar, British engineers built a military aviation base. Up to 8,000 British servicemembers were stationed in the islands, which at that time had 30,000 inhabitants.

The Faroe Islands were repeatedly attacked by German aircraft, suffering minimal damage. That said, 25 Faroese ships were lost and 132 sailors died.

Iceland

From 1918 until 1944, Iceland was in a personal union with the Danish king (King Christian X) being the head of state of both Denmark and Iceland. The United Kingdom occupied Iceland on 10 May 1940 to preempt German occupation, turning it over to the then-neutral United States in July 1941, before the latter's entry into the war in December 1941. Officially remaining neutral throughout World War II, Iceland became an independent republic on 17 June 1944.

Greenland

On 9 April 1941, the Danish envoy to the United States, Henrik Kauffmann, signed a treaty with the United States, authorizing it to defend Greenland and construct military stations there. Kauffmann was supported in this decision by the Danish diplomats in the United States and the local authorities in Greenland. Signing this treaty "in the name of the King" was a clear violation of his diplomatic powers, but Kauffmann argued that he would not receive orders from an occupied Copenhagen.

Protectorate government (1940–43)