Between 639 and 641 the Muslim Arabs of the Rashidun Caliphate conquered Byzantine Egypt. In 641 or 642 and again in 652 they invaded Nubia but were repelled, making the Nubians one of the few who managed to defeat the Arabs during the Islamic expansion. Afterwards the Makurian king and the Arabs agreed on a unique non-aggression pact that also included an annual exchange of gifts, thus acknowledging Makuria's independence. While the Arabs failed to conquer Nubia they began to settle east of the Nile, where they eventually founded several port towns and intermarried with the local Beja.