Having reached Tunisia Rommel launched an attack against the U.S. II Corps which was threatening to cut his lines of supply north to Tunis. Rommel inflicted a sharp defeat on the American forces at the Kasserine Pass in February.
Rommel immediately turned back against the British forces, occupying the Mareth Line (old French defences on the Libyan border). But Rommel could only delay the inevitable. At the end of January 1943, the Italian General Giovanni Messe had been appointed the new commander of Rommel's Panzer Army Africa while Rommel had been at Kasserine, which was renamed the Italo-German Panzer Army (in recognition of the fact that it consisted of one German and three Italian corps). Though Messe replaced Rommel, he diplomatically deferred to him, and the two coexisted in what was theoretically the same command. On 23 February Armeegruppe Afrika was created with Rommel in command. It included the Italo-German Panzer Army under Messe (renamed 1st Italian Army) and the German 5th Panzer Army in the north of Tunisia under General Hans-Jürgen von Arnim.
The last Rommel offensive in North Africa was on 6 March 1943, when he attacked Eighth Army at the Battle of Medenine. The attack was made with 10th, 15th, and 21st Panzer Divisions. Warned by ULTRA intercepts, Montgomery deployed large numbers of anti-tank guns in the path of the offensive. After losing 52 tanks, Rommel called off the assault. On 9 March he handed over command of Armeegruppe Afrika to General Hans-Jürgen von Arnim and left Africa, because of health reasons, never to return. On 13 May 1943, General Messe surrendered the remnants of Armeegruppe Afrika to the Allies.
Some historians contrast Rommel's withdrawal to Tunisia against Hitler's wishes with Friedrich Paulus's obedience of orders to have the German Sixth Army stand its ground at the Battle of Stalingrad which resulted in its annihilation. Field Marshal Albert Kesselring, appointed overall Axis commander in North Africa, saw things differently. He believed the withdrawals, some of which were carried out against his orders, unnecessary and ruinous since they brought forward British airfields ever closer to the port of Tunis. As far as he was concerned, Rommel was an insubordinate defeatist and string-puller. The increasingly acrimonious relations between the two did nothing to enhance performance.