Western Afghanistan comprising the provinces of Heart (whose name is derived from Hari-Rud which is said to be a derivation from the older term Hari-Rudra - two Hindu dieties), Kandahar (the ancient Gandhara of the Mahabharata) was ruled by Sabuktagin a Muslim ruler from a town named Ghazni. He was facing Raja Jaya Pala who ruled from Kubha (modern Kabul) in Eastern Afghanistan. His kingdom comprised the provinces of Kapisa on the western side of the Hindu Kush Ranges and Punjab on the Eastern side. (Incidentally, his kingdom was like that of Ambhi who ruled approximately the same provinces, when Alexander the Great had invaded the area in 330 B.C.E.)
The year 980C.E. marks the beginning of the Muslim invasion into India proper when Sabuktagin attacked Raja Jaya Pal in Afghanistan. Afghanistan is today a Muslim country separated from India by another Muslim country Pakistan. But in 980 C.E. Afghanistan was also a place where the people were Hindus and Buddhists. The name "Afghanistan" comes from "Upa-Gana-stan" which means in Sanskrit "The place inhabited by allied tribes". This was the place from where Gandhari of the Mahabharat came from Gandhar whose king was Shakuni. The Pakthoons are descendants of the Paktha tribe mentioned in Vedic literature. Till the year 980 C.E., this area was a Hindu majority area, till Sabuktagin from Ghazni invaded it and displaced the ruling Hindu king - Jaya Pal Shahi.
The place where Kabul's main mosque stands today was the site of an ancient Hindu temple and the story of its capture is kept alive in Islamic Afghan legend which describes the Islamic hero Sabuktagin who fought with a sword in every hand to defeat the Hindus and destroy their temple to put up a Mosque in its place. (This is not being mentioned here to reclaim the place as a temple. But to record a long forgotten fact that today's Islamic battlefield of the Taliban was once inhabited by Hindus.)
The victory of Sabuktagin pushed the frontiers of the Hindu kingdom of the Shahis from Kabul to behind the Hindu Kush mountains (Hindu Kush is literally "killer of Hindus" - a name given by Mahmud Ghazni to describe the number of Hindus who died on their way into Afghanistan to a life of captivity) . After this setback, the Shahis shifted their capital from Kubha (Kabul) to Udbhandapura (modern Und in NWFP). Sabuktagin's son Mahmud Ghazni, kept up the attacks on the Shahis and captured Und. Subsequently, the Shahis moved their capital to Lahore and later to Kangra in Himachal.
The defeat of the Shahis opened up the Gangetic plains to the Muslims and Mahmud Ghazni repeatedly attacked the main Hindu kingdoms ruled by the Gurjara-Pratiharas and sacked Hindu temples. The main ruler in those days was Rajyapala Pratihara who resisted Mahmud Ghazni's raids, partly successfully. In his last attack on Somnath, Mahmud Ghazni successfully sacked the temple at Prabhasa Patan in Gujarat, but on his way back he was roundly defeated by the Gujar rulers of North Gujarat. Mahmud never came back to India after that. (Refer to the Glory that was Gujar Desha by K.M. Munshi) But these first Muslim raids into India proper had given an ominous indication of what was to come a couple of centuries later in the year 1194 C.E.
But for now, the Muslim rule of the Ghaznivids was established in Kabul, Paktoonistan and in the land of the five rivers - Punjab. Thus after Sindh in 715; Kabul, Paktoonistan, and Punjab became the next Indian provinces which went under Muslim domination in the period 980 C.E. to 1020 C.E.