The Turkish Commander-in-Chief of the Samanid forces, the hajib Alp-Tegin, in 350/961 allied with the vizier Abu 'Ali Muhammad Balaami to place their own candidate for the amirate on the throne. The coup failed, and Alp-Tegin was obliged to withdraw to Ghazna in eastern Afghanistan, on the far periphery of the Samanid empire, wresting the town from its local ruling dynasty of the Lawiks (351/962). Ghazna was not, however, relinquished by the Lawiks without a struggle. They were connected by marriage to the Hindushahi dynasty ruling in Kabul, and clearly enjoyed much local support. During the next fifteen years, they returned on various occasions, and at one juncture, Abu Ishaq Ibrahim, Alp-Tegin's son and successor in Ghazna, only regained the town with military help sent out from Bukhara. Because of this need in the early years for Samanid support, the various Turkish governors in Ghazna continued down to Sebuk-Tegin's death in 387/997 generally to acknowledge the amirs on their coins.
One of Alp-Tegin's most trusted supporters was the ghulam Sebuk-Tegin (probably to be interpreted as Turkish "beloved prince"). According to a testament of aphorisms on the exercise of kingly power, allegedly left to his son Mahmud (the Pand-ndma), Sebiik-Tegin came from the region of Barskhan on the shores of the Isiq-Gol, in what is now the Kirghiz S.S.R. It is accordingly probable that he came from one of the component tribes of the Turkish Qarluq group. Obsequious genealogists later fabricated a genealogy connecting Sebiik-Tegin with the last Sasanid Emperor, Yazdgard III, it being supposed that Yazdgard's family had fled into the Central Asian steppes and there intermarried with the local Turks, although they were unable to get round the fact of his pagan birth. Captured in the course of intertribal warfare, he was sold as a slave at Nakhshab, and eventually bought by AlpTegin. The story of his rise to eminence in Alp-Tegin's service is detailed in the Siydsat-ndma of Nizam al-Mulk, although this account should be treated with some caution. Sebiik-Tegin accompanied Alp-Tegin to Ghazna, passing into the service of the latter's son Abu. Ishaq Ibrahim, and quietly building up a following among the Turks in Ghazna. He was prominent during the governorship of Bilge-Tegin, in whose time the town of Gardiz was first attacked (364/974). In 366/977 the Turks of Ghazna deposed the drunken and incompetent governor Bori, and installed Sebiik-Tegin as their governor and leader, thereby giving the stamp of formal approval to the substance of power which he had previously enjoyed.