In the 9th century Islamic peace was changed by the intervention of the Carolingian court to the south of the Pyrenees. The Upper Region of al-Andalus was in turmoil because of internal fighting between the Muslim leaders of High Aragon.
At this point of the civil war, two soldiers came from rebel lines to swear allegiance to the emirate; one was Jalaf ibn Rasid who was allied to rebel leader Bahlul ibn Marzuq. In the year 802, Jalaf changed his way of thinking and stood up to Bahlul, who had to take refuge in the castle at Barbastro. After then being expelled from the castle he was killed by Jalaf who took over his property and possessions in Huesca and Barbitaniya.
Jalaf made his headquarters in Barbastro, extending and fortifying the incipient city and maintaining his power there until 861, the year he died. He was succeeded by his son, Abd Allah ibn Jalaf, who remained relatively independent from Cordoba power during the emirates of Al Hakam I and Abd al Rahman II. Jalaf ibn Rasid ibn Asad is remembered most as the person responsible for the construction of the castle in Alquézar and for the creation of the city of Barbastro.