 Marching on Cordoba, they defeated Saqaliba general Wadih and forced Muhammad II al-Mahdi to flee to Toledo.They then installed Sulayman as caliph, and based themselves in the Madinat al-Zahra to avoid friction with the local population.Wadih and al-Mahdi formed an alliance with the Counts of Barcelona and Urgell and marched back on Cordoba.