In 639 an army of some 4,000 men were sent against Egypt by the second caliph, Umar, under the command of Amr ibn al-As. This army was joined by another 5,000 men in 640 and defeated a Byzantine army at the battle of Heliopolis. Amr next proceeded in the direction of Alexandria, which was surrendered to him by a treaty signed on 8 November 641. Alexandria was regained for the Byzantine Empire in 645 but was retaken by Amr in 646. In 654 an invasion fleet sent by Constans II was repulsed. From that time no serious effort was made by the Byzantines to regain possession of the country.