After commissioning, the ship underwent a lengthy
work up process, which was common for German destroyers during the Second World War. Following
Z31 being damaged in a collision with a schooner on 6 November 1941, she was transferred to an operational flotilla in Norwegian waters in December 1942. On 30 December 1942,
Z31 left the
Altafjord in northern Norway along with the
heavy cruisers and
Lützow and the destroyers
Friedrich Eckoldt,
Richard Beitzen,
Theodor Riedel, and on
Operation Regenbogen, an attempt to attack the
Arctic convoy JW 51B. The German force encountered the convoy on the morning of 31 December, and in poor visibility, engaged the convoy's escort in the
Battle of the Barents Sea.
Hipper sank the British destroyer and the minesweeper and damaged the destroyers and , while
Lützow damaged the destroyer , but broke off the engagement after the British cruiser covering force of and damaged
Hipper and sank
Richard Beitzen. None of the 15 merchant ships in the convoy were damaged. On 5–6 February 1943,
Z31,
Theodor Riedel and the minelayer laid a minefield off
Kildin Island, while on 10–11 March the two destroyers escorted
Lützow from
Kaafjord to
Narvik. On 6 September 1943,
Z31 set out from the Altafjord as part of a fleet consisting of the battleships and and nine destroyers on
Operation Zitronella, a raid on Allied-controlled
Spitzbergen.
Z31 was hit eight times by shells from coastal artillery off
Barentsburg on 8 September, with one man killed and a second wounded. In November,
Z31 transferred to southern Norway, where she carried out patrol operations before laying defensive minefields in the entrance to the
Skagerrak from 4–7 December. After that operation,
Z31 began a refit at
Wesermünde, which continued until August 1944, when she returned to Norway. She was damaged by strafing from British carrier-based fighters during
an attack on
Tirpitz in the Altafjord on 29 August. The destroyer continued escort and patrol duties for the rest of the year, On 25 January 1945, the German 4th Destroyer Flotilla, consisting of
Z31, and set out from
Tromsø for the
Baltic. On 28 January, the three destroyers
were intercepted by the British cruisers and in the
Sognefjorden, north of
Bergen.
Z31 was hit seven times by the British ships, with her forward turret being wrecked and 55 men killed and a further 24 wounded.
Z34 was also damaged. After escaping,
Z31 put into Bergen for temporary repairs, with further work being carried out at
Horten and
Oslo before the ship reached the Baltic. From 22 March,
Z31, working with
Z34 and
Lützow, shelled advancing Soviet troops near Gotenhafen in
West Prussia (now
Gdynia in Poland), while on 23 March she towed the hulk of the battleship to the entrance of Gotenhafen harbour, ready to be sunk as a
blockship. (
Gneisenau was
scuttled on 27 March). On 27 March, a 15 cm shell accidentally exploded in one of
Z31s guns, killing four and wounding 18. Nevertheless,
Z31 continued to support evacuation of German troops and civilians from Gotenhafen and
Hela, until the ship was damaged by Soviet bombs, and withdrew westwards with and
Lützow on 8 April.
Z31 was docked at Swinemünde (now
Świnoujście) for repair on 10 April, and was damaged again by Soviet air attack when on passage to
Kiel on 27 April. She reached
Brunsbüttel on 30 April, and remained there until the end of the war on 8 May. ==French service==