But the Ghaznavid troops had been unable immediately to restore Qawam al-Daula to his former position, and when towards the end of Mahmud's reign, a fresh succession dispute broke out in Kirman, he made no attempt to intervene. It is somewhat surprising that Mahmud refrained so long from attacking Jibal, with its capital of Ray, a rich manufacturing centre and strategically the key to northern Persia; for since the death of the Buyid Fakhr al-Daula 'All in 387/997 and the succession of his infant son Majd al-Daula Rustam, de facto power there had been in the hands of a woman, the Queen-Mother Sayyida. It is recorded in Baihaqi that towards the end of his life, Mahmud was asked by his vizier Maimandl why he had not before intervened in Jibal. The sultan replied that if a man had been ruling in Ray, he would have had to keep an army permanently stationed at Nishapur, whereas, with a woman in Ray, there was no real Biiyid threat to Khurasan.
Sayyida's death in 419/1028 left Majd al-Daula with sole power in Ray, but the last years of his exclusion from real authority had sapped his powers to govern effectively; he was unable to keep his Daiiami troops in order, and foolishly appealed to Mahmud for help. It is probable that Mahmud was already meditating intervention, and when his army reached Ray, he deposed Majd al-Daula and sacked the city in a frightful manner. The sultan felt bound to justify this act of naked aggression, and in his fath-nama to the caliph spoke of cleansing Jibal of the "infidel Batiniyya and evil-doing innovators", who had flourished under Majd al-Daula's lax rule; certainly, those suspected of extremist Shi'I and Mu'tazill beliefs were mercilessly hunted down, and many allegedly heretical books burnt. The seizure of Ray opened up the possibility of a drive towards Azarbaljan and the west. Mas'ud was given charge of operations here. The Musafirid ruler of Dailam, Ibrahim b. Marzuban, was temporarily dispossessed of his capital Tarum and brought to obedience; and then at the beginning of 421/ 1030 Mas'ud turned southwards against the Kakuyids of Isfahan and Hamadan. The news of his father's death in Ghazna compelled him, however, to leave the Kakuyid 'Ala' al-Daula Muhammad b. Dushmanziyar, called Ibn Kakuya, as his vassal in Isfahan. As it happened, Mas'ud was never able permanently to subdue the resilient Ibn Kakuya, and Ghaznavid rule in Ray only lasted for some seven years. Yet the Ghaznavids had seriously impaired the Daiiami ascendancy in northern Persia, so that the advance of the Saljuqs through northern Persia a few years later was made correspondingly easier.
So far we have been concerned only with Ghaznavid expansion into Central Asia and the Iranian world. Yet simultaneously, a great military effort was being mounted against India. Each winter, armies of the regular troops, swollen by the ghazis and volunteers who flocked thither from all parts of the eastern Islamic world, would descend to the plains of India in search of Hindu temples to sack and slaves to round up. The numerous Indian campaigns of Mahmud have been well described by Muhammad Nazim, with a skilful elucidation of the geographical and topographical problems involved in the source material. The first great obstacle to Ghaznavid penetration of India was the continued existence of the Hindushahi kingdom of Waihind, with whose Raja, Jaipal, Sebiik-Tegin had already clashed. In 392/1001 Mahmud defeated and captured Jaipal near Peshawar, so humiliating him that he committed suicide. His son Anandpal organized a grand coalition of the Indian rulers of northwestern India, but this too was broken by the sultan at Waihind and Nagarkot (399/1009). The next Hindushahis, Trilochanpal and his son Bhimpal, carried on the fight against Mahmud in alliance with such rulers as Ganda, Raja of Kalinjar, but were gradually driven eastwards across the Punjab, and with the death of Bhimpal in 417/1026, the once-mighty Hindushahi dynasty came to an end.
Mahmud was not, of course, the first Muslim leader to bring Islam to India. The new faith had been implanted in Sind by the Arab general Muhammad b. al-Qasim al-Thaqafi in Umayyad times (90-2/709-11), and had spread up the Indus as far as Multan. During the course of the 4th/ioth century, the Muslim communities of Sind had been won over by Isma'ill dd'is or missionaries to the cause of extremist Shiism. The early Ghaznavids vigorously uprooted all traces of Isma'ilism in their own dominions, and when in 403/1012-13 the Fatimid caliph in Cairo, al-Hakim, sent a diplomatic mission to Mahmud, the sultan had the luckless envoy executed. Thus Mahmud had, in his own eyes, ample reason for taking over the important town of Multan and restoring orthodoxy there. In two campaigns of 396/1006 and 401/1010, the local ruler Abu'-Fath Da'ud was humbled and finally deposed, and the Isma'ilis in the city massacred. Nevertheless, Isma'ilism lasted there for two more centuries; and only thirty years after Mahmud's efforts there, in Maudud b. Mas'ud's sultanate, a rising of the Multan Isma'ilis occurred.