In 1178 the Ghurid ruler Mu'izz al-Din Muhammad invaded the southern part of Ghaznavid Punjab and reached as far as Gujarat. In 1179/80 he seized Peshawar, and by 1181/2 swept around Lahore, but Khusrau Malik managed to keep him from the city by paying him. However, Lahore was finally captured by the Ghurids in 1186, while Khusrau-Malik and his son Bahram-Shah were taken to Ghur and imprisoned, marking the end of the Ghaznavid Empire.
More on https://en.wikipedia.org/wiki/Khusrau_Malik