After the beginning of
Operation Barbarossa, the German invasion of the Soviet Union, in June 1941, Shafranov was given command of the 778th Artillery Regiment of the
247th Rifle Division of the
31st Army of the
Reserve Front in July. From October he was chief of artillery of the
249th Rifle Division, fighting with the
22nd and
4th Shock Armies on the
Kalinin and
Northwestern Fronts. In fighting for
Peno,
Andreapol,
Toropets, and
Velizh during January and February 1942, Shafranov was credited with "skillfully organizing artillery-infantry cooperation and artillery fire support", for which he received the
Order of the Red Banner on 31 January 1942. He continued in his position after the 249th was converted into the
16th Guards Rifle Division in March. Shafranov, by this time a
colonel, became commander of the division on 16 August, and was promoted to major general on 27 November. He led the division in defensive battles in the
Staritsa area as part of the
30th Army of the
Western Front until February 1943. During March, in the
Rzhev–Vyazma Strategic Offensive, Shafranov, promoted to major general, "skillfully organized the breakthrough of forward enemy defenses" before the division crossed the
Volga and captured
Rzhev. Subsequently, with the
11th Guards Army of the
Bryansk Front, he led the division in
Operation Kutuzov and the battles for
Karachev and
Gorodok in mid-1943. For the "successful performance of combat missions" in Operation Kutuzov, Shafranov was awarded the
Order of Kutuzov, 2nd class. Appointed commander of the
36th Guards Rifle Corps in early September, Shafranov led the latter as part of the 11th Guards Army with the
Bryansk,
2nd and
1st Baltic, and
3rd Belorussian Fronts during the offensives of 1943 and 1944. For his "skillful leadership" of the corps in the late June 1944
Vitebsk–Orsha Offensive of
Operation Bagration, during which it made a flank maneuver and captured the rail junction of
Orsha, he was awarded the
Order of Bogdan Khmelnitsky, 2nd class. During the July
Kaunas Offensive, the corps crossed the
Neman and advanced in three days, capturing
Kalvarija. He was promoted to lieutenant general on 13 September. Given command of the
5th Army of the 3rd Belorussian Front on 16 October, Shafranov transferred to command the 31st Army of the
1st Ukrainian Front on 15 December, leading the latter for the rest of the war. Under his command, the army fought in the
East Prussian Offensive, capturing
Schirwindt,
Labiau,
Wehlau, and
Tapiau, which covered the approaches to
Königsberg. Continuing the offensive, the army captured
Heiligenbeil, the last German stronghold on the coast of the
Frisches Haff to the south of Königsberg, and completed the destruction of the surrounded German troops in East Prussia during March. For his "skillful leadership", Shafranov was awarded the title
Hero of the Soviet Union and the
Order of Lenin on 19 April 1945. He ended the war in the
Prague Offensive in early May. == Postwar ==