The Ghaznavid dynasty (غزنویان Ġaznaviyān) or the Ghaznavid Empire was a Persianate Muslim dynasty and empire of Turkic mamluk origin, ruling at its greatest extent, large parts of Persia, Khorasan, much of Transoxiana and the northwest Indian subcontinent from 977 to 1186. The dynasty was founded by Sabuktigin upon his succession to the rule of Ghazna after the death of his father-in-law, Alp Tigin, who was an ex-general of the Samanid Empire from Balkh, north of the Hindu Kush in Greater Khorasan.
Sabuktigin's son, Mahmud of Ghazni, expanded the Ghaznavid Empire to the Amu Darya, the Indus River and the Indian Ocean in the east and to Rey and Hamadan in the west. Under the reign of Mas'ud I, the Ghaznavid dynasty began losing control over its western territories to the Seljuk Empire after the Battle of Dandanaqan in 1040, resulting in a restriction of its holdings to modern-day Afghanistan, Pakistan and Northern India.
In 1151, Sultan Bahram Shah lost Ghazni to the Ghurid sultan Ala al-Din Husayn. The Ghaznavids retook Ghazni, but lost the city to the Ghuzz Turks who in turn lost it to Muhammad of Ghor. In response, the Ghaznavids fled to Lahore, their regional capital. In 1186, Lahore was conquered by the Ghurid sultan, Muhammad of Ghor, with its Ghaznavid ruler, Khusrau Malik, imprisoned and later executed.
Two military families arose from the Turkic slave-guards of the Samanid Empire, the Simjurids and Ghaznavids, who ultimately proved disastrous to the Samanids. The Simjurids received an appanage in the Kohistan region of eastern Khorasan. The Samanid generals Alp Tigin and Abu al-Hasan Simjuri competed for the governorship of Khorasan and control of the Samanid Empire by placing on the throne emirs they could dominate after the death of Abd al-Malik I in 961. His death created a succession crisis between his brothers.
A court party instigated by men of the scribal class – civilian ministers rather than Turkic generals – rejected the candidacy of Alp Tigin for the Samanid throne.