and hurt the caliphate. Early on, it provided the government with a stable force to address domestic and foreign problems. However, creation of this foreign army and al-Mu'tasim's transfer of the capital from Baghdad to Samarra created a division between the caliphate and the peoples they claimed to rule. In addition, the power of the Mamluks steadily grew until Ar-Radi (934–41) was constrained to hand over most of the royal functions to Muhammad ibn Ra'iq. Under the Mamluk Sultanate of Cairo (1261–1517) In 1261, following the Mongol conquest of Baghdad, the Mamluk rulers of Egypt tried to gain legitimacy for their rule by declaring the re-establishment of the Abbasid caliphate in Cairo. The Abbasid caliphs in Egypt had little political power; they continued to maintain the symbols of authority, but their sway was confined to religious matters. The first Abbasid caliph of Cairo was Al-Mustansir (r. June–November 1261). The Abbasid caliphate of Cairo lasted until the time of Al-Mutawakkil III, who ruled as caliph from 1508 to 1516, then he was deposed briefly in 1516 by his predecessor Al-Mustamsik, but was restored again to the caliphate in 1517. The Ottoman Great Sultan Selim I defeated the Mamluk Sultanate and made Egypt part of the Ottoman Empire in 1517. Al-Mutawakkil III was captured together with his family and transported to Constantinople as a prisoner where he had a ceremonial role. He died in 1543, following his return to Cairo. Parallel regional caliphates in the later Abbasid Era The Abbasid dynasty lost effective power over much of the Muslim realm by the first half of the tenth century. The Umayyad dynasty, which had survived and come to rule over Al-Andalus, reclaimed the title of caliph in 929, lasting until it was overthrown in 1031. Umayyad Caliphate of Córdoba (929–1031) During the Umayyad dynasty, the Iberian Peninsula was an integral province of the Umayyad Caliphate ruling from Damascus. The Umayyads lost the position of caliph in Damascus in 750, and Abd al-Rahman I became Emir of Córdoba in 756 after six years in exile. Intent on regaining power, he defeated the existing Islamic rulers of the area who defied Umayyad rule and united various local fiefdoms into an emirate. Rulers of the emirate used the title "emir" or "sultan" until the 10th century, when Abd al-Rahman III was faced with the threat of invasion by the Fatimid Caliphate. To aid his fight against