In 639, Egypt was a prefecture of the Byzantine Empire. However, it had been occupied just a decade before by the Sasanian Empire under Khosrau II (616 to 629 CE). The power of the Byzantine Empire was shattered during the Muslim conquest of Syria, and therefore the conquest of Egypt was much easier. In 639 some 4000 Rashidun troops led by Amr ibn al-As were sent by Umar to conquer the land of the ancient pharaohs. The Rashidun army crossed into Egypt from Palestine in December 639 and advanced rapidly into the Nile Delta. The imperial garrisons retreated into the walled towns, where they successfully held out for a year or more. However, the Muslims sent for reinforcements, and the invading army, joined by another 12,000 men in 640, 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. The Thebaid seems to have surrendered with scarcely any opposition.