In 977 AD, the Turkic ruler Sabuktigin acceded to the throne of the small kingdom of Ghazni in central Afghanistan. In the 980s, Subuktigin defeated the Shahis, extending his rule from the Khyber Pass, to the Indus. After his death in 997, his son Mahmud assumed power in Ghazni. He expanded his father's kingdom far to the west and east through military conquest. He invaded the Punjab and northern India seventeen times during his reign, conquering the Shahi kingdom and extending his rule across the Punjab as far as the upper Yamuna. Mahmud demolished Hindu temples wherever his campaigns took him, and he also attacked the Ismailis, whom he viewed as heretics.
Mahmud's successors, known as the Ghaznavids, ruled for 157 years.