The Ghaznavid Empire was a state in the region of today's Afghanistan that existed from 977 to 1186. It was created by Turks under Khan Sebük Tigin with the city Ghazna (Ghazni) as capital, replacing the Samanids. Sebük Tigin made himself lord of nearly all the present territory of Afghanistan and of the Punjab. In 997, Mahmud, the son of Sebük Tigin, succeeded his father upon his death, and with him Ghazni and the Ghaznavid dynasty have become perpetually associated. Issuing forth year after year from the capital, Mahmud carried fully seventeen expeditions of devastation through northern India and Gujarat, as well as others to the north and west. From the borders of Kurdistan to Samarkand, from the Caspian Sea to the Yamuna, his authority was acknowledged.
The wealth brought back 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, and his son Mas'ud was unable to control the conquered lands and lost the Battle of Dandanqan in 1040. Even though there was some revival of importance under Ibrahim (1059-1099), the empire never reached anything like the same splendour and power. It was soon overshadowed by the Seljuk Turks of Persia. The Ghaznavid Empire ended in 1149 with the capture of Ghazna by the Ghurids. Ghaznavid power in northern India continued until the conquest of Lahore in 1186.
Before 1160, the Ghaznevid empire covered an area running from central Afghanistan east to the Punjab, with capitals at Ghazni, a city on the banks of Ghazni river in present-day Afghanistan, and at Lahore in present-day Pakistan.
He raided eastwards into the remaining Ghaznevid territory, and invaded Gujarat in the 1180's, but was rebuffed by Gujarat's Solanki rulers.
In 1186-7 he conquered Lahore, ending the Ghaznevid empire and bringing the last of Ghaznevid territory under his control.