By 971, Ghālib held the rank of
vizier (
wazīr). 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. He was apparently too late. An Leonese embassy arrived from
Astorga with news that the Vikings had gone up the
river Duero as far as
Santaver (
Shantabarīya), although they had left empty-handed. Ghālib's fleet did not sail from Almería until the end of Ramadān, around 25 July. The fleet failed to make contact with the Vikings and returned to port a month later. A triumph was staged for Ghālib nonetheless. He was escorted into Córdoba with banners all the way to the
Alcázar, and a panegyric was composed in his honour. He did not, however, command the response to the Vikings the following year. In 972, Ghālib was promoted to the new rank of
al-qāʾid al-aʿlā (supreme commander). In 974, diplomas of authority (
sijilāt) were issued to the lords of the Middle March upon Ghālib's request. In them, Ghālib is described as the
zaʿīm (boss) of the marcher lords. He was thus at the peak of his power and influence when in 973 he was sent to Africa to bring the
Idrīsids back under ʿUmayyad control. They had defected under pressure to the Fāṭimids in 958. He returned to Córdoba in triumph with the deposed Idrīsid leader,
al-Ḥasan ibn Gannūn, as his captive in September 974. The Idrīsid ruler was forced to swear allegiance to the ʿUmayyads and to the
Mālikī madhab (as opposed to the
Shiism of the Fāṭimids). In 975, Ghālib led an expedition against the alliance of León and Navarre. He won two major victories, defeating the allied force under
Ramiro III of León that was
besieging Gormaz on 28 June and then defeating Count
García Fernández of Castile south of the
Duero, near
Langa, on 8 July. After these victories he was given two gilded swords and the honorific
Dhu ʾl-Sayfayn (Lord of the Two Swords), a title which had also been granted by the
ʿAbbāsid regent
al-Muwaffaq in Baghdad to his general
Isḥāq ibn Kundāj in 883. 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. ==Conflict with Ibn Abī ʿĀmir==