The Ghaznavids dynasty was founded by Subaktagin, a Turkish slave who had been converted to Islam. It was formed during the long battle of the Samanids, who were Iranians by descent, with the Turkish tribesmen towards the end of the ninth century. The battle against Turks, who were non-Islamic, was a struggle for religion as well as the safety of the state. In this matter Ghaznavids were as much missionaries as fighters. It was their resourcefulness and willingness to undergo great privations for the sake of Islam, that enabled the infant muslim states of central Asia to hold their own against the Turkish. With the downfall of the Samanid kingdom, the task of defending the Islamic land from the Central Asian tribesmen was taken over by the Ghaznavids. It was during the reign of Mahmud of Ghazni (998-1030 AD) that the spirit of the Ghaznavids increased, because of his stout defense against the Central Asian Turkish tribal invaders. Another reason for the increase in spirit was Mahmudís close association with the renaissance of the Iranian cultural spirit which took place during this period.
Mahmud played an important role in the defense of the Islamic States against the Turkish tribes and in the Iranian cultural renaissance. But in Indian History he is more a plunderer and destroyer of temples than a defender of Islam.
Following the death of Mahmud, a powerful empire, the Seljuk Empire consisting of Syria, Iran and Trans-Oxiana, came into being. The Seljuk Empire contended with the Ghaznavids for the control of Khorasan. In a famous battle, Masud, the son of Mahmud, was completely defeated and had to flee to Lahore for refuge. The Ghaznavid empire now shrunk to Ghazni and the Punjab. They were now in no position to pose a serious military danger to India. Simultaneously, a number of new states arose in north India which could counter the Ghaznavid raids.
The Ghanavi state finally collapsed in 1186 and were assimilated by the Oguz.