Alptigin, one of the Turkish slaves of the Samanid ruler, Abdul Malik, rose to the status of Governor of Khurasan. However, when his patron died, he was striped of his title and forced to leave the land. He captured a small area in Afghanistan and established his rule in the city-state of Ghazni in 962 with the aim of conquering his own land, a desire that remained in the hearts of his successors. After his death in 977, his son-in-law, Subuktigin, succeeded him. Under Subuktigin, Ghazni started emerging as a political and military power of the region. Alarmed at the rising power in the neighborhood, the Hindu Shahi Raja Jaipal attacked Ghazni. Jaipal was defeated. In order to save his life, he promised to pay tribute. But after going back home, he not only defaulted but also took support from other Hindu Rajas of the region and again attacked Subuktigin in 991. His fate was not different this time. He was defeated and had to pay a heavy ransom besides giving away the areas of Lamghan and Peshawar.
Meanwhile, Subuktigin died and his son Mahmud ascended the throne in 998. Jaipal took advantage of the situation, and to avenge his defeat at the hands of Subuktigin, organized an army of twelve thousand horsemen, thirty thousand foot soldiers and three hundred elephants. This movement forced Mahmud, who was preparing to invade Central Asia, to turn his attention towards India. The battle against Jaipal was the beginning of a long series of attacks by Mahmud against South Asia. According to most historians, Mahmud invaded India seventeen times to crush the power of the Hindu Rajas and Maharajas who were always busy planning conspiracies against him. After defeating Tarnochalpal in 1021, Mahmud formally annexed Punjab. After the fall of Punjab, the Hindu think tank assembled at Somnath – which was more of a political center than a temple – to plan a big war against Mahmud. He took all the Rajas and Maharajas by surprise when he attacked Somnath and crushed the Hindu headquarter of political intrigue. With the destruction of Somnath he broke the backbone of the Hindus in the region and thus had no need to attack