It was established in the early 11th century as one of the many Taifa kingdoms that followed the collapse of the Caliphate of Córdoba around this time.
During the first part of this period (1013–1038), the city was ruled by the Arab Banu Tujib tribe.
They were replaced by the Arab Banu Hud rulers, who had to deal with a complicated alliance with El Cid of Valencia and his Castilian masters against the Almoravids, who managed to bring the Taifas Emirates under their control.
After the death of El Cid, his kingdom was conquered by the Almoravids, and by 1100 they had crossed the Ebro into Barbastro, which brought them into direct confrontation with Aragon.
The last sultan of the Banu Hud, Abd-al-Malik, and Imad ad-Dawla of Saraqusta, were forced to abandon the capital.