Jayapala was the last great king of this dynasty. His empire extended from west of Kabul to the river Sutlej. However, this expansion of Gandhara kingdom coincided with the rise of the powerful Ghaznavid Empire under Sabuktigin. Defeated twice by Sabuktigin and then by Mahmud of Ghazni in the Kabul valley, Jayapala committed suicide. Anandapala, a son of Jayapala, moved his capital near Nandana in the Salt Range. In 1021 the last king of this dynasty, Trilochanapala, was assassinated by his own troops which spelled the end of Gandhara. Subsequently, some Shahi princes moved to Kashmir and became active in local politics.
The city of Kandahar in Afghanistan is said to have been named after Gandhara. According to H.W. Bellow, an emigrant from Gandhara in the 5th century brought this name to modern Kandahar. Faxian reported that the Buddha's alms-bowl existed in Peshawar Valley when he visited around 400 (chapter XII). In 1872 Bellow saw this huge begging bowl (seven feet in diameter) preserved in the shrine of Sultan Wais outside Kandahar. When Olaf Caroe wrote his book in 1958 (Caroe, pp. 170–171), this relic was reported to be at Kabul Museum. The present status of this bowl is unknown.
Al Biruni writing c. 1030 CE, reported on the devastation caused during the conquest of Gandhara and much of northwest India by Mahmud of Ghazni following his defeat of Jayapala at Peshawar in 1001 CE:
"Now in the following times no Muslim conqueror passed beyond the frontier of Kâbul and the river Sindh until the days of the Turks, when they seized the power in Ghazna under the Sâmânî dynasty, and the supreme power fell to the lot of Nâṣir-addaula Sabuktagin. This prince chose the holy war as his calling, and therefore called himself al-Ghâzî ("the warrior/invader"). In the interest of his successors he constructed, in order to weaken the Indian frontier, those roads on which afterwards his son Yamin-addaula Maḥmûd marched into India during a period of thirty years and more. God be merciful to both father and son ! Maḥmûd utterly ruined the prosperity of the country, and performed there wonderful exploits, by which the Hindus became like atoms of dust scattered in all directions, and like a tale of old in the mouth of the people. Their scattered remains cherish, of course, the most inveterate aversion towards all Muslims. This is the reason, too, why Hindu sciences have retired far away from those parts of the country conquered by us, and have fled to places which our hand cannot yet reach, to Kashmir, Benares, and other places. And there the antagonism between them and all foreigners receives more and more nourishment both from political and religious sources."[18]
“ During the closing years of the tenth and the early years of the succeeding century of our era , Mahmud the first Sultan and Musalman of the Turk dynasty of kings who ruled at Ghazni , made a succession of inroads twelve or fourteen in number , into Gandhar – the present Peshwar valley – in the course of his proselytizing invasions of Hindustan .[19] ”
“ Fire and sword havoc and destruction , marked his course everywhere . Gandhar which was styled the Garden of the North was left at his death a weird and desolate waste . Its rich fields and fruitful gardens, together with the canal which watered them (the course of which is still partially traceable in the western part of the plain),had all disappeared . Its numerous stone built cities , monasteries ,and topes with their valuable and revered monuments and sculptures , were sacked , fired razed to the ground , and utterly destroyed as habitations [19]