By late 10th century the Muslim presence in Sindh had deteriorated to two insignificant families in control of Multan and Mansurah. Kabul and surrounding neighborhood was under the control of Hindu kings from the middle of 9th century. A dynasty called the Shahis flourished here and extended their kingdom up to Punjab in the east. Then in the year 870 Kabul was lost to invading Muslims. A Turkic slave, Aptigin by name, had amassed power and occupied Ghazni, an important town on the Kabul-Kandahar road, in the year 963. Aptigin's son Sabuktigin succeeded him in the year 977. He was anxious for religious war with the Hindus and ravaged the provinces of Kabul and Punjab.
Shahi dynasty under King Jayapala still controlled the area west of Jalalabad and thus part of what is known as Kabul valley. He resisted the onslaught gallantly but had to sue for peace when the weather turned hostile during the treacherous winter of Afghanistan.
Sabuktigin with his later to be infamous son, Mahmud, gorged on the Hindu population with butchery and sorcery, the likes of which had not been seen before in the subcontinent. Jayapala gathered a large army with the help of neighboring kingdoms and mounted a counter attack. The Ghazni forces were more mobile and superior riders compared to the slower elephant-mounted Indians. They were routed and the Khyber Pass and countless number of elephants and other booty fell into the hands of Sabuktigin. The invaders had a foothold on the Indian soil and controlled the gateway, the Khyber Pass, to the vast Indian subcontinent.
After the death of Sabuktigin his son, Mahmud succeeded him. He was to be to India what a Satan was to Islam. Grotesquely ugly in appearance Mahmud controlled a vast empire and had ambitions of expanding further east into the heartland of India. With the god given right of every Muslim to root out idolatry as an excuse, he started his assault into India. He resolved on a pattern of yearly incursion into India with the charade of spreading Islam to the infidels. However, he had heard of the fabled wealth of India and was in dire need of capital to maintain his large armed forces and entourage.
The religious mission quickly changed to indiscriminate looting and murdering of Hindus with large caravans of bounty marching back to Ghazni after each monsoon. The first assault was on November 27, 1001. A concurrent, though biased, account of the assault was kept by his faithful secretary al-Utbi and later a more reliable account was given by historian Ferishta. It was during his second invasion near Peshawar the much-weakened King Jayapala suffered a crushing defeat of enormous proportions. Following this the proud king abdicated his throne to his son Anandapala and committed suicide by climbing onto his own funeral pyre.
Mahmud continued his raid into India on a regular basis (a total of seventeen times over twenty-seven years, from 1001-1027) and the Shahis were the only kings to oppose him, but with little success. Large assortments of loot including precious jewels and pearls, tons of gold and silver were hoarded on thousands of elephants and transported to Ghazni. The Indians headed for the hills with the sound of advancing troops of the Muslim army and there was no significant opposition to the ugly marauder. City after city, year after year felt the wrath of Ghaznivads. Pillaging of the cities was invariably followed by rape and murder.
Then in the year 1008 it was the turn of Mathura with its well-endowed temple of Lord Krishna. Before razing it to the ground and plundering it, Mahmud is said to have marveled at the sheer beauty of the architecture and imagined it would take him two hundred years to build a similar magnificent mosque. However, he had no difficulty in desecrating and looting the temple of tons of gold, silver and precious stones before burning it. The taste of blood and booty had practically blinded him so much so that even the Muslim sympathetic, sycophant historians felt uncomfortable writing about his ruthless murderous rampage.
The Shiva temple of Somnath was one of his last targets. Somnath in Gujarat (Saurashtra) had a fortified temple with its most sacred and celebrated lingam. The people, however, were pacifists and defenseless. In 1025, Mahmud with only cavalry and camels crossed the Thar Desert and surprised the residents of Somnath. When the soldiers scaled the walls with ladders all they found inside were defenseless worshippers. Fifty thousand devotees praying to the lingam and weeping passionately with hands clasped around their necks were massacred in cold blood. The marauders looted twenty million dirhams-worth of gold and silver. Mahmud himself took great pleasure in destroying the stone lingam, after stripping it off its gold ornaments. Bits of the lingam were sent back to Ghazni and incorporated into the steps of its new mosque to be trampled and perpetually defiled by the faithful.
Eventually Anandapala's empire shrank to a small part of northeast Punjab. His son Trilochanapala even lost that last bit of land and became a refugee in Kashmir. In his zeal to accumulate wealth, Mahmud neglected to administer to the lands he had conquered. He finally died in the year 1030 but not before he transformed Ghazni into a worthy capital from the looted wealth. India breathed a collective sigh of relief. Mahmud had two sons born on the same day to two different wives and a dispute ensued after his death. This manner of horrific bloodbath and murderous plots before each succession was to become common practice among the Muslim rulers of India for the rest of their history. The reign of Masud was insignificant and eventually the Ghaznivads lost their famed capital of Ghazni to invading Turks. Lahore served as their capital for next several decades.
Kashmir, although cut off by impregnable mountain barriers from the rest of the world, always had very deep cultural and political relations with her neighbors. She had her diplomatic relations with China and other countries in the north. Lalitaditya led his armies as far as Gobi desert in the north. For long the exploits of Lalitaditya, which have been narrated in the Raj Tarangni quite in detail, were treated by scholars as a mere figment of the imagination of Kalhana, but ruler of Sindh, Dahar's letter to Bin Qasim, to which reference has been made earlier, has set at rest all the controversy on this score. Dahar's letter finds its place in Chhachhinama, which is an account of the war between Dahar and Bin Qasim given by an Arab eyewitness. The nearest Hindu Kingdom to Kashmir was that of Kabul. With Kabul, Kashmir was tied with bonds of religion, but she had also political relations with her, which lasted for a number of centuries as will be presently seen. Reference may in this behalf be made to Alberuni, an Arab scholar who came to India with Mahmud of Gazni in the beginning of 11th century and stayed in India for a number of years.
Alberuni has left a book on India, in which he has given with great scholarly precision an account of the social, political, and economic conditions of the then India. Alberuni writes that, "the Hindus had kings residing in Kabul. The last king of this race (Kshatriya) was Lagutarman and his wazir was Kallar, a Brahman. Lagutarman had bad manners and worse behavior, so the Vazier put him in chains and occupied the royal throne. After him ruled Brahman kings named Samand, Kamalu, Bhim, Jaipal, Anandpal and Tarojanpal (Trilochanpal).'' Out of the seven Brahman kings of Kabul mentioned by Alberuni, we find mention of four in Kalhana's Raj Tarangini, with this difference that Kalhana calls the first king Lalliya and not as Kallar as Alberuni calls him, the other three being Kamluka, Bhima and Trilochanpal. Kalhana wrote his history in 1148 A. D. about 125 years after the fall of Trilochanpal, who according to Alberuni was killed in 1021 A. D.
There is one thing very interesting about the Hindu Kings of Kabul, and that they were known as Shahs, and their dynasty as Hindu Shahis of Kabul
About the time when Lalliya, the Brahman Vazier of the last Kshatriya king, usurped the throne of Kabul, there reigned in Kashmir a strong ruler by name Shankara Varman. His reign lasted from 883 A.D. to 902 A.D. Shankara Varman was as noticed earlier a sagacious ruler, who made his country great, both militarily and economically. He started many industries and greatly encouraged trade and commerce, though he is described also as an oppressive ruler whose exactions from the people as taxes were exorbitant. One thing very important about him was that he established a direct relation with the common people and talked their language instead of Sanskrit. For all this he is very much criticized and taunted by Kalhana, the Brahman author of Rajtarangini. But by such methods he must have secured a substantial backing from his people. Whether it was for securing markets for the articles of Kashmir manufacture or simply to win military glory, Shankara Varman went out of Kashmir at the head of a military expedition, and conquered all the neighboring principalities including Gujrat, which was according to Rajtarangini ruled under the overlordship of Kabul by a king named Ala Khan. Lalliya, the Brahman ruler of Kabul, came to the help of his vassal, Ala Khan, but was defeated and driven out of his own country. The easy victory which the Kashmir ruler Shankara Varman achieved over Lalliya has to be attributed to the fact that Lalliya was a usurper with no title to the throne and had therefore struck no deep roots in men's minds and consequently must have received very little help from the people. But the occupation of Kabul by an outsider stirred the patriotism of the people of Kabul and a resistance movement was the result.
The people of Kabul were then, as they are now, very patriotic and seldom brooked interference from outside. They fought Arabs and other Muslim rulers from 663 A.D. to 1021 A.D. but never accepted their suzerainty.
The occupation of Kabul by Shankara Varman only led to a grim struggle, which reached its climax during the reign of Gopal Varman (902 to 904 A.D.), who succeeded Shankara Varman; and another military expedition was sent by the Kashmir ruler under a General by name Prabhakar Deva to restore order and tighten the grip. The Kashmiri General though successful did not press his victory too far. He had realized by his experience that the people of Kabul could not be kept for long under subjection. He started negotiations with them and agreed to install Lalliya's son by name Toramana on the Kabul throne. This was done and Toramana ascended the Kabul throne under a new name or title, Kamluka, which was given to him by Prabhakar Deva. As already seen, Alberuni in his list of Kabul kings describes him as Kamlu. Henceforth, the relations between Kabul and Kashmir became very cordial and in course of time marriage relations came to be established between the ruling dynasties of the two countries, which further strengthened the mutual bonds of amity, and concord. Kshema Gupta who ruled Kashmir from 951 - 959 A.D. married the granddaughter of Bhima, who is described by Alberuni as the fourth Brahman King to rule Kabul after Lalliya. We have it on the authority of Kalhana that this Kabul King Bhima came to Kashmir and stayed there for some time and built a temple dedicated to Vishnu which was given the name of Bhima Keshava. The dedication of a temple to Vishnu would show that the Hindu Shahis of Kabul were Vaishnavites and not Buddhists as some take pleasure in describing them as such. The temple of Bhima Keshava is even now existing in a village now known as Bumzu near Mattan, though as a Muslim Ziarat, and is now known as Ziarat Bam Din Sahib
The name of Bhima's granddaughter was Didda who ruled Kashmir after her husband's death as sole sovereign from 980 A.D. to 1003 A.D. She appointed her brother's son Sangrama Raj as heir to the throne. By now the Turkish king, Subaktagin had occupied Ghazni and Kabul Shahis came face to face with a rising power, which within a short period liquidated the Hindu Shahi rule in Kabul. But the struggle was grim and a stout resistance was offered both by Jaipal and his son Anandapal and his grandson Trilochanpal. Kashmir also participated in these wars, as Queen Didda of Kashmir was closely related to Jaipal, son of Bhima. But Rajtarangini is silent on that. But to the final resistance, which was organized by the last Shahi King, Trilochanpal, Kashmir also made her contribution. This time Sangram Raj, (1003 - 1028 A.D.) Diddas' son was on the Kashmir throne. The Kashmir ruler sent well-equipped force under a Minister by name Tunga. But unfortunately the methods of warfare of Tunga and Trilochanpal were different. Trilochanpal was in favor of using the traditional Kabul methods of war are which consisted of retiring into mountain fastnesses and from there start depredations on the enemy, cutting his line of communications and harassing his rear. Trilochanpal counseled the adoption of such methods. But the Kashmir General who was both vain and inglorious did not heed the advice and came down to the plains and engaged in battle with Mahmud. Kalhana gives a graphic description of this battle. Says that Trilochanpal and some Kashmiris of royal blood fought very bravely, but the chances of victory, thanks to the tactical blunder made by Tunga receded back very far. The last resistance movement on the Kabul soil was finally crushed. The defeat of Trilochanpal had very far-reaching effects. The Punjab fell an easy victim to Mahmud who occupied it as a Province. The whole of India now lay bare before any invader who might have chosen to creep in, though for another two centuries no serious invasion was either planned or made.
After the fall of Trilochanpal, his sons, Rudrapal, Diddapal, Kshempala and Anangpala went to Kashmir and settled there under royal patronage. Here also they distinguished themselves by their deeds of valour. Not long after they had settled in Kashmir, that the country was attacked by some warlike tribes from the north. All the four Pal brothers took part in the defense of Kashmir and distinguished themselves by their acts of bravery. Thereafter nothing is heard about the descendants of Trilochanpal, excepting that Harsha, a Kashmiri king was involved in a civil war and one of his Ranis who was connected with Trilochanpal, distinguished herself in actual warfare. What type of kings were these great Hindu Shahi rulers of Kabul becomes clear from a remark of Alberuni who says that: “The Hindu Shahiya dynasty is extinct and of the whole house there is not the slightest remnant in existence. We must say that in all their grandeur, they never slackened in the ardent desire of doing that which is good and right, that they were men of noble sentiment and noble bearing.”
Kalhana in his Raj Tarangini expresses grief over the fall of Trilochanpal in the following words: “We have described the prosperity of the Shahi country during the days of Shankara Varman. Now we think in our minds with great grief, where is the Shahi dynasty with its ministers, its kings, and its great grandeur? Did it exist really or did it not? Tunga returned to his own country Kashmir, totally defeated, and left the whole Bharata land open to the descent of the Turshkas.” He further expresses his anguish in these words: “The very name of the splendor of Shahi kings has vanished. What is not seen in dream, what even our imagination cannot conceive, that destiny accomplishes with ease.”