At the beginning of the Second World War Wagner was Naval Attaché in Madrid, Spain. The "Wagner Campaign" was named after him, via which from January to August 1940 300 tons of strategic commodities, mainly tungsten, were exported from Spain to Germany for war materials use. The transaction was accounted with deliveries of German arms, mercenary services and transports to Spain. Still after 1 September 1939, the outbreak of World War II, airplane parts were delivered to Spain. The German exports to Spain which had increased during the Spanish Civil War were mainly carried out by sea. With the outbreak of World War 2 the Allies tried to block this sea route trade, and "the Wagner campaign" was devised to organize German merchant ships that were stuck thereafter in Spanish ports changing their flags and partially subscribe them to Spanish entrepreneur Juan March. During the course of World War 2 Wagner became head of the Operational Department of the naval staff. At the end of the conflict, Wagner, together with the supreme commander of the Kriegsmarine, Hans Georg von Friedeburg, was present and a signatory to the surrender of the German forces in northern Germany at Lüneburg Heath on 4 May 1945 to the British Commander-in-Chief, General Bernard Montgomery. Wagner subsequently gave testimony on 13 and 14 May 1946 at the Nuremberg Trials.
Post-war activities
Wagner was a member of the "Naval Historical Team" based in Bremerhaven, which consisted of a group of German Naval officers appointed by the United States Navy to write down the war experiences of German naval forces from a German point of view in the conflict. The group produced a report in 1949 entitled Soviet anti-submarine warfare potential , detailing missions of the German U-boats U-9, U-18, U-19, U-20, U-23, U-24, U-576, U-752, U-986, and U-997 in the years from 1942 to 1945. In 1951 via the Naval Historical Team Wagner authored a paper entitled "A Critique on Vice-Admiral Eberhard Weichold's essay on 'German surface ships—policy and operations in World War II'". Two papers known as 'Bremerhaven or Wagner memoranda' were also produced by the Group on the creation of a new post-war German Navy: "Aufbau eines deutschen Marinekontingents im Rahmen deutscher Mitwirkung an der Verteidigung Westeuropas ", the so-called Wagner's memorandum, dated March 1951, and "Ausführungen des deutschen Marinesachverständigen, Konteradmiral a.D. Gerhard Wagner über Fragen des deutschen Marinebeitrages ", 8 February 1952.
In the post-war Navy of West Germany Wagner was appointed to the post of Deputy to the Navy Inspector. He was the first flag officer to hold the position of the integrated North Atlantic Treaty OrganizationCommander Naval Forces Baltic Approaches from 1961 to 1962, which was initially titled 'Commander Allied Naval Forces Northern Area Central Europe'. In this post he held the temporary rank of Vice-Admiral.