From June 1940 to June 1941 Legnani, as the commander of the 8th Naval Division, participated in the battles Calabria, Taranto and Cape Matapan, as well as in countering the British operations "Hats" (29 August-1 September 1940) and "MB 5" (29 September to 2 October 1940), aimed at supplying Malta. After leaving the command of the 8th Division, on 10 December 1941 he was appointed commander of the Italian submarine fleet (replacing Admiral Mario Falangola), a role that he kept after his promotion to admiral in 1942. He directed Italian submarine operations in the Mediterranean until the 8 September 1943 armistice; in this period he was also decorated with the German Iron Cross second-class, as well as Officer's Cross of the Military Order of Savoy.