By the end of the ninth century A.D., the Abbasid Caliphate declined. The Turkish governors established independent kingdoms and the Caliph became only a ritual authority. One among them was Alptigin whose capital was Ghazni. His successor and son-in-law Sabuktigin wanted to conquer India from the north-west. He succeeded in capturing Peshawar from Jayapala. But his raids did not produce a lasting effect. He was succeeded by his son, Mahmud
Mahmud is said to have made seventeen raids into India. At that time, North India was divided into a number of Hindu states. On the frontier of India, there existed the Hindu Shahi kingdom which extended from the Punjab to Kabul. The other important kingdoms of north India were Kanauj, Gujarat, Kashmir, Nepal, Malwa and Bundelkhand. The initial raids were against the Hindu Shahi kingdom in which its king Jayapala was defeated in 1001. After this defeat, Jayapala immolated himself because he thought that his defeat was a disgrace. His successor Anandapala fought against Mahmud but he was also defeated in the Battle of Waihind, the Hind Shahi capital near Peshawar in 1008. In this battle, Anandapala was supported by the rulers of Kanauj and Rajasthan. As a result of his victory at Waihind, Mahmud extended his rule over most of the Punjab.
The subsequent raids of Mahmud into India were aimed at plundering the rich temples and cities of northern India. In 1011, he raided Nagarkot in the Punjab hills and Thaneshwar near Delhi. In 1018, Mahmud plundered the holy city of Mathura and also attacked Kanauj. The ruler of Kanauj, Rajyapala abandoned Kanauj and later died. Mahmud returned via Kalinjar with fabulous riches. His next important raid was against Gujarat. In 1024, Mahmud marched from Multan across Rajaputana, defeated the Solanki King Bhimadeva I, plundered Anhilwad and sacked the famous temple of Somanatha. Then, he returned through the Sind desert. This was his last campaign in India. Mahmud died in 1030 A.D.
Mahmud was not a mere raider and plunderer of wealth. He built a wide empire from the Punjab in the east to the Caspian sea on the west and from Samarkand in the north to Gujarat in the south. The Ghaznavid empire roughly included Persia, Trans-oxyana, Afghanistan and Punjab. His achievements were due to his leadership and restless activity. Mahmud was considered a hero of Islam by medieval historians. He also patronized art and literature. Firdausi was the poet-laureate in the court of Mahmud. He was the author of Shah Namah. Alberuni stayed in Mahmud's court and wrote the famous Kitab-i-Hind, an account on India. His conquest of Punjab and Multan completely changed the political situation in India. He paved the way for the Turks and Afghans for further conquests and make deeper incursions into the Gangetic valley at any time. He drained the resources of India by his repeated raids and deprived India of her manpower. The exhaustion of India's economic resources and man power had its adverse effect on the political future of India. The Hindu Shahi kingdom was guarding the gates of India against foreign invaders. Mahmud destroyed it and thus India's frontiers became defenceless. The inclusion of Punjab and Afghanistan in Ghazni's kingdom made the subsequent Muslim conquests of India comparatively easy.