The Ghaznavid Empire was a Khorāṣānian Sunni Muslim state, founded by a dynasty of Turkic mamluk origin, which existed from 975 to 1187. It was centered in Ghazni, a city in present Afghanistan, and ruled much of Persia, Transoxania, and the northern parts of the Indian subcontinent. Due to the political and cultural influence of their predecessors - that of the Persian Ṣāmānī dynasty - the originally Turkic Ghaznavids had become thoroughly Persianized..
The dynasty was founded by Sebuktigin upon his succession to rule of territories centered around the city of Ghazni from his father-in-law, Alp Tigin, a break-away ex-general of the Ṣāmānī sultans. Sebuktigin's son, Shah Mahmoud, expanded the empire in the region that stretched from the Oxus river to the Indus Valley and the Indian Ocean; and in the west it reached Rayy and Hamadan. Under the reign of Mas'ud I it experienced major territorial losses. It lost its western territories to the Seljuqs in the Battle of Dandanaqan resulting in a restriction of its holdings to Afghanistan, Balochistan and the Punjab. In 1151, Sultan Bahram Shah lost Ghazni to Ala'uddin Hussain of Ghor and the capital was moved to Lahore until its subsequent capture by the Ghurids in 1186.
Two military families arose from the Turkic Slave-Guards of the Samanids — the Simjurids and Ghaznavids — who ultimately proved disastrous to the Samanids. The Simjurids received an appanage in the Kohistan region of eastern Khorasan. Alp Tigin founded the Ghaznavid fortunes when he established himself at Ghazna (modern Ghazni, Afghanistan) in 962. He and Abu al-Hasan Simjuri, as Samanid generals, competed with each other for the governorship of Khorasan and control of the Samanid empire by placing on the throne emirs they could dominate when Abdul Malik I of Samanid died in 961. But when the Samanid Emir Abdul Malik I died in 961 CE it created a succession crisis between Abdul Malik's brothers. A court party instigated by men of the scribal class—civilian ministers as contrasted with Turkic generals—rejected Alp Tigin's candidate for the Samanid throne. Mansur I was installed, and Alp Tigin prudently retired to his fief of Ghazna. The Simjurids enjoyed control of Khorasan south of the Oxus but were hard-pressed by a third great Iranian dynasty, the Buwayhids, and were unable to survive the collapse of the Samanids and the rise of the Ghaznavids.
The struggles of the Turkic slave generals for mastery of the throne with the help of shifting allegiance from the court's ministerial leaders both demonstrated and accelerated the Samanid decline. Samanid weakness attracted into Transoxania the Qarluq Turks, who had recently converted to Islam. They occupied Bukhara in 992 to establish in Transoxania the Qarakhanid, or Ilek Khanid, dynasty. Alp Tigin had been succeeded at Ghazna by Sebüktigin (died 997). Sebüktigin's son Mahmud made an agreement with the Qarakhanids whereby the Oxus was recognized as their mutual boundary.
The wealth brought back from the Indian expeditions to Ghazni was enormous, and contemporary historians (e.g. Abolfazl Beyhaghi, Ferdowsi) give glowing descriptions of the magnificence of the capital, as well as of the conquerors munificent support of literature. Mahmud died in (1030). Even though there was some revival of importance under Ibrahim (1059-1099), the empire never reached anything like the same splendor and power. It was soon overshadowed by the Seljuqs of Iran.
Mahmud's son Mas'ud was unable to preserve the empire and following a disastrous defeat at the Battle of Dandanaqan in (1040) lost all the Ghaznavid lands in Iran and Central Asia to the Seljuks and plunged the realm into a "Time of troubles". Mas'ud's son Ibrahim who re-established a truncated empire on a firmer basis by arriving at a peace agreement with the Seljuks and a restoration of cultural and political linkages. Under Ibrahim and his successors saw a period of sustained tranquility for the empire. Shorn of its western land it was increasingly sustained by riches accrued from raids across Northern India where it faced stiff resistance from Rajput rulers such as the Paramara of Malwa and the Gahadvala of Kannauj. Signs of weakness in the state became apparent when Masud III died in 1115 with internal strife between his sons ending with the ascension of Sultan Bahram Shah as a Seljuk Vassal. Sultan Bahram Shah, was the last Ghaznavid King ruling Ghazni, the first and main Ghaznavid capital. Ala'uddin Hussain, a Ghorid King, conquered the city of Ghazni in 1151, for the revenge of his brother's death. He razed all the city, and burned it for 7 days, after which he got famous as "Jahānsoz" (World Burner). Ghazni was restored to the Ghaznavids by the intervention of the Seljuks who came to Behrams aid. Ghaznavid struggles with the Ghurids continued in the subsequent years as they nibbled away at Ghaznavid territory and Ghazni and Zabulistan was lost a group of Oghuz Turks before captured by the Gurids. Ghaznavid power in northern India continued until the conquest of Lahore from Khusrau Malik in 1186.
The Ghaznavid empire grew to cover much of present-day Iran, Afghanistan, and northwest India and Pakistan, and the Ghaznavids are generally credited with launching Islam into Hindu-dominated India. In addition to the wealth accumulated through raiding Indian cities, and exacting tribute from Indian Rajas the Ghaznavids also benefited from their position as an intermediary along the trade routes between China and the Mediterranean. They were however unable to hold power for long and by 1040 the Seljuks had taken over their Persian domains and a century later the Ghurids took over their remaining sub-continental lands.