Ibn Marwan, hearing of an impending attack by the Emirate forces, had fled northwards from Badajoz,settling in the castle of Karkar (now Carquere, near present Lamego, Portugal).
Afterwards, at Ibn Marwân's request, King Alfonso III of Asturias had sent him auxiliary troops and the combined army had defeated the Emirate forces.
Returning to Badajoz, now a well fortified city, he establishes his rule throughout the whole of the Al'Garb Al'Andalus, "The West", the name given by the Moors of Iberia to the modern region of Algarve and, by extension, to most of Portugal, during their rule of the territory.