Rommel was stopped in the First Battle of El Alamein from the momentum gained in the aftermath of the Battle of Gazala, which had seemed to lead him to Cairo.
The recent victory had a cost for the German General, as by lengthening the line of communications, the supply had become more expensive and more vulnerable to air attacks or raids of the British special forces. This aside from the fact that the British had information about the ships supplying the Afrika Korps, which made much of the supplies that Rommel's men were waiting to reach the seabed.
On the other hand, the supply line had shortened for the British, their human and material resources being in full growth. The British forces, including their allies, had numerical superiority in men, tanks, and aircraft.
The defensive line at El Alamein chosen by the British Eighth Army's commander, General Claude Auchinleck, was bordered in the north by the Mediterranean Sea, and at only 40 miles (64 km) south by the impassable Qattara Depression. Rommel's favorite maneuver of attack on flanks was thus impossible, and the only option was a frontal assault.
By Kirrages (Own work) [CC BY-SA 3.0 (http://creativecommons.org/licenses/by-sa/3.0/deed.en)], via Wikimedia Commons
On July 1, 1945, shortly after the arrival at the defensive positions established by the British, "the Desert Fox" went on the offensive, hoping to exploit the positive trend following the Battle of Gazala. Spearheading the attack were the Afrika Korps German divisions: in the north, there was the 90th Light Afrika Division, while in the center were the 15th and 21st Panzer Division.
The German attack began on the night, but the advance of the 90th Light Division was soon stopped by the 1st South African Division, while the artillery of the 10th Indian Infantry Division, supported by British tanks, repelled the two panzer divisions which attacked towards Ruweisat Ridge.
Furious attacks of the Desert Air Force in subsequent days also contributed to increasing losses among the Afrika Korps forces. In these circumstances, Rommel decided to stop the attack and ordered his troops to prepare defensive positions.
Starting with July 8th until the end of the month, the British Eighth Army launched a series of attacks against the Axis positions, trying to take advantage of its numerical superiority and better supply. The Allied forces had a promising start, taking a large number of Italian prisoners, but the lack of coordination between the Eighth Army's branches and the Afrika Korps riposte, prevented a decisive victory.
The positive aspect for the British was that they had stopped Rommel and the Axis forces had suffered significant losses. The ground was prepared for victory in the Second Battle of El Alamein, obtained after Lieutenant-General Bernard Montgomery took command of the Eighth Army.