Ghālib's rise coincides with the retirement of ʿAbd al-Raḥmān III from active military command following his defeat at the Battle of Simancas in 939.
[1] In his final year, Ghālib became embroiled in a civil war with his own son-in-law, Ibn Abī ʿĀmir (Almanzor).
[6][1][7] In this capacity, according to al-Maqqarī, a late source, he rebuilt the castle of Medinaceli (Madīnat Sālim) and used it as a base to harass the Christian kingdom of León.
In 953, he attacked the Leonese county of Castile, bringing back many prisoners and much booty, but the border remained unchanged.
[4] In 960, ʿAbd al-Raḥmān III restored the deposed Sancho I to the Leonese throne in exchange for ten border fortresses.
On 3 July that year, he was summoned by the Caliph al-Ḥakam and put in charge of mounting a campaign by land and sea against a Viking fleet that had appeared off the Atlantic coast.
After making preparations, Ghālib departed on 12 July through the Madīnat al-Zahrā (Eastern Gate) in an elaborate ceremony.
An Leonese embassy arrived from Astorga with news that the Vikings had gone up the river Duero as far as Santaver (Shantabarīya),[10] although they had left empty-handed.
Only al-Ḥakam himself, his son Hishām and his first minister, Jaʿfar ibn ʿUthmān al-Muṣḥafi, were present at the ceremony where Ghālib received the honour.
Establishing his headquarters at Medinaceli, Ghālib brought Ibn Abī ʿĀmir, the future ruler of Córdoba, into his employ as his intendant general and was followed by many others drawn by word of his latest honour.
[4][8][12] After the accession of Hishām II in October 976, Ghālib took command of the military forces of the capital and Ibn Abī ʿĀmir followed him there.
[15] Ibn Abī ʿĀmir rewarded his father-in-law's cooperation by procuring for him the honorific dhu ʾl-wizāratayn ("he of the two vizierates") from the young Hishām II.
[2] Son-in-law and father-in-law soon had a falling-out over Ibn Abī ʿĀmir's restricting the caliph's sphere of activity to religious ceremonies.
[2] With the conflict now in the open, Ibn Abī ʿĀmir seized Medinaceli at the head of a large Berber army.