Gandhar was a great kingdom for thousands of years. I know that Sindh was first won in 712 AD by Muhammed Bin Kasim from the last Hindu king of Sindh, Dahir. But I have never heard of extinction of Hindus from Afghanistan. Who was the last Hindu king of Upaganasthan/Gandhar? Till when were Hindus dominating that land?
The year 980 C.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. Today the city of Gandhar is known as Kandahar. 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. Shiva worship was widespread in Afghanistan. There was a time when the entire region was replete with hundreds of Shiva temples celebrating Shiva – Parvati worship and abuzz with Shiv chants, prayers, legends and worship. Archaeological excavations in this region conducted by Sir Estine (an East India Company official) led to the recovery of uncountable shrines and inscriptions. He has authored four books on that topic featuring photos of icons, icons and inscriptions discovered. The photos show a sun temple and a Ganesha statue too. An Islamabad University professor Abdul Rehman has authored two books on those finds recalling the glory and prosperity of those times. Regimes of two Hindu rulers “Kusham” and “Kidara” lasted for fairly long periods. During their rule a number of Shiva temples were not only in Afghanistan but in other West Asian regions too. Uzbekistan and Takzikistan formed part of the Afghan kingdom in those times. Tashkent has one of those ancient Shiva temples standing even today. Professor Abdul Rehman states that Bukhara region Was known as “Shah Vihar” in ancient times. It was ruled by an Hindu king. When Arabs invaded that kingdom its queen traveled to Kashmir to seek military help. Arab chronicles mention her as 'Khatoon', meaning ’Woman’. Baku (capital of the Azerbaijan region) known for its underground petroleum yields has still an ancient Hindu temple of the Divine Flame generated by the subterranean petrol and gas). During the Czar regimes in Russia a Punjabi priest officiated at that temple. The walls display some religious stanzas written in Punjabi Gurumakhi script. The market there also had Hindu merchants. Nearby was a locality too of Hindu inhabitants. Baku in Azerbaijani language actually signifies a Goddess. Therefore obviously Baku derives its name from a very ancient Vedic Goddess temple there Kenduj a province of Afghanistan, was ruled by a king that had a Hindu prime minister. This is mentioned in history books. Albirruni’s travel account contains details of ancient Hindu Afghanistan, He mentions a Hindu king, Khingla whose coins bore the imprint of Shiva. The first ruler of that dynasty was Viahitagni. History mentions a Shiva temple in Gardej township, which was plundered by Arab invaders. Khingla dynasty ruled the region from 666 to 843 A.D. From 843 to 850 A.D. a Brahmin Minister ruled the region. The Kalkaa community of Brahmins had acquired prominence in those times. They were later known as Kallers. A township of that name exists in Punjab. Prominent among them who find a mention in later history are Samantdev, Bheemdev, Jaipaldev, Anandpal and Trilochan. Jaipaldev suffered a defeat in 1002 when Mohammed Ganzavi invaded India. Unable to bear that defeat Jaipaldev committed suicide. When Hsüan-tsang visited the region early in the 7th century CE, the Kabul valley region was ruled by a Hindu Kshatriya king, who is identified as the Shahi Khingal, and whose name has been found in an inscription found in Gardez. The Hindu Shahi kings of Kabul and Gandhara may have had links to some ruling families in neighboring Kashmir and other areas to the east. 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.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 recovery and significance of the inscription, telling a story of the Hindu ruler Veka and his devotion to lord 'Shiva', was told by leading epigraphist and archaeologist Prof Ahmad Hasan Dani of the Quaid-E-Azam University of Islamabad at the Indian History Congress. Veka is said to have conquered the earth, the markets and the forts by his eight-fold forces, suggesting that he must have himself gained success against the Arab rulers of southern Afghanistan.During the rule of the Hindu Shahi ruler Bhimapala there was a break in the dynasty - one branch, headed by Jayapala, ruled in Lamaghan and Punjab, and another branch, headed by Veka, ruled in northern part of Afghanistan. The northern branch must have come to an end by the conquest of Alptigin in the second half of tenth century AD"
(Wisdom courtesy: Subodh Kapoor)
Source of this information can be found here