Berling did not participate in the Polish defence effort during the Invasion of Poland in 1939. After the city ofVilnius was occupied by the Soviet Union under the terms of the Molotov–Ribbentrop Pact, Berling, along with many other Polish officers, was arrested by the Soviet secret police. He remained in prison until 1940, first in Starobilsk and later Moscow, eventually agreeing to cooperate with the Soviets. After the Sikorski–Mayski agreement of 17 August 1941, Berling was nominated to be chief of staff of the recreated 5th Infantry Division, and later commander of the temporary camp for Polish soldiers in Krasnovodsk. Berling refused to leave the Soviet Union with the army led by Władysław Anders, of which Berling was formally a member. Along with two other officers, he was tried in absentia before an Anders' Army court which sentenced them to death. The sentence was vacated by General Kazimierz Sosnkowski, the Polish commander-in-chief of forces loyal to the Londongovernment in exile. district of Warsaw, 1944 From 1940, Berling had been involved in efforts to create a Polish division in the Soviet Union, at first within the Soviet Red Army. In September 1942 and during the following months, he and Wanda Wasilewska appealed to Joseph Stalin for permission to establish the Polish division. On 8 April 1943, Berling proposed the establishment of a new Polish army; permission was granted after the break in Soviet-Polish diplomatic relations. In May 1943, the communist-led Polish People's Army was created in the Soviet Union. It was a new formation of Polish Armed Forces in the East. Berling was nominated to be the commander of its first unit, the 1st Tadeusz Kościuszko Infantry Division, and was promoted to general by Stalin. He became the overall deputy commander of the Polish Army on the Eastern Front on 22 July 1944. On 1 August 1944, the underground Polish Home Army, loyal to the Polish government-in-exile in London, began the 63-day long Warsaw Uprising, an attempt to free the city from the occupying German forces before the arrival of the Red Army. On 15–23 September, when the uprising was in its later phase, with his First Polish Army on the east bank of the Vistula River and the Praga district of Warsaw already secured, Berling led a rescue effort that involved crossing the Vistula and establishing a bridgehead on the west bank. The failed operation, possibly not fully consulted with Berling's Soviet military superiors, resulted in heavy Polish Army casualties and may have caused Berling's dismissal from his post soon thereafter. He was transferred to the War Academy in Moscow, where he remained until his return to Poland in 1947. In Poland, Berling organized and directed the Academy of General Staff. He retired from the military in 1953.