While Muhammad took refuge in Toledo, Sulayman entered Córdoba, which he allowed to be sacked by Berbers and Castillans; he freed and recognized caliph Hisham II, only to depose him after a few days.
He was thus elected caliph by his Berber troops, assuming the title (laqab) of al-Musta'in bi-llah ("He Who Seeks for God's Help").
In May 1010 Muhammad, who had reorganized his troops of "slave" mercenaries from all over Europe and had allied with Count Ramon Borrell of Barcelona, defeated Sulayman and conquered Córdoba, which was plundered by the Spaniards.
His policy of concessions to Berbers, Arab and "slave" troops and leaders, effectively reduced the caliphate's authority to only Córdoba.
In 1016 Córdoba was attacked by a large Berber army under the Hammudid governor of Ceuta, Ali ibn Hammud al-Nasir, who conquered it on 1 July 1016.