On 17 June 1940, the headquarters of British 6th Infantry Division was designated as the Western Desert Force. The unit consisted of the 7th Armoured Division and the Indian 4th Infantry Division. The unit was commanded by Major-General Richard O'Connor.
From December 1940 to February 1941, during Operation Compass, the exploits of the Western Desert Force earned a parody of Winston Churchill's famous quote, "Never has so much been owed by so many, to so few." So many Italians were captured by the Western Desert Force that it was said, "Never has so much been surrendered by so many, to so few."
The Western Desert Force was retitled XIII Corps on January 1, 1941 and was broken up in February 1941. In September 1941 the static HQ Cyrenaica command was redesignated XIII Corps to control the British Commonwealth forces along the Egypt - Libya border and became part of the newly created Eighth Army, which was formed in September 1941. The Corps remained part of the Eighth Army throughout the rest of the North African Campaign which finished when the Axis forces in Tunisia surrendered in May 1943.
XIII Corps took part in the Allied invasion of Sicily in July 1943 and when Sicily fell, moved to the Italian mainland, campaigning with the Eighth Army on the Adriatic front until the end of 1943. In May 1944 the corps had switched with much of Eighth Army's strength to the centre of the Allied front at Cassino and during the fourth Battle of Monte Cassino was responsible for effecting a successful opposed crossing of the Garigliano and Rapido rivers, breaking into the heart of the German defenses in the Liri valley.
At the end of 1944 XIII Corps was transferred to the United States Fifth Army to become its right wing high in the Apennine mountains for the fighting on the Gothic Line. By April 1945 the Corps had returned to Eighth Army for the Spring 1945 offensive in Italy which ended in May 1945 with the surrender of Axis forces in Italy. Units of the XIII Corps confronted Yugoslav troops at Trieste, entering and capturing the city. The corps restored order in the strife-ridden city and enforced the Morgan Line from May 1945 to mid-1946.