The Turk Shahis were a dynasty of Western Turk, or mixed Turco-Hephthalite origin, that ruled from Kabul and Kapisa to Gandhara in the 7th to 9th centuries CE."The advance of Islamic forces both into Tokharistan in the north and into Zabulistan farther south was opposed by local rulers of probably Western Turkish identity" in They may have been of Khalaj ethnicity."The new rulers of Kabul, who according to me were Khalaj Turks, extended their rule over the former territory of the Kapisi kingdom [Kapisa to Gandhara], while a branch of them became independent in Zabulistan. A Korean monk Huichao (慧超) who visited these regions in the third decade of the 8th century, reported that both regions were ruled by the Turkish kings." The Gandhara territory may have been bordering the Kashmir kingdom to the east. From the 560s, the Western Turks had gradually expanded southeasterward from Transoxiana, and occupied Bactria and the Hindu Kush region, forming largely independent polities."The period from 560 CE onwards would be that of the Western Turks, although it is not clear how and foremost when they gained power over Bactria and the Hindukush-region. Minoru Inaba states that "gradually having extended their power, they came to be independent ..."" in The Turk Shahis may have been a political extension of the neighbouring Western Turk Yabghus of Tokharistan. In the Hindu Kush region, they replaced the Nezak Huns – the last dynasty of Bactrian rulers with origins among the Xwn (Xionite) and/or Huna peoples (who are sometimes also referred to as "Huns" who invaded Eastern Europe during a similar period).

The Turk Shahis arose at a time when the Sasanian Empire had already been conquered by the Rashidun Caliphate. The Turk Shahis then resisted for more than 250 years the eastward expansion of the Abbasid Caliphate, until they fell to the Persian Saffarids in the 9th century CE. The Ghaznavids then finally broke through into India after overpowering the declining succeeding Hindu Shahis and Gurjaras.

Kabulistan was the heartland of the Turk Shahi domain, which at times included Zabulistan and Gandhara.

Territorial extents The Turks under the Western Turk ruler Tong Yabghu Qaghan crossed the Hindu Kush and occupied Gandhara as far as the Indus River from circa 625 CE. Overall, the territory of the Turk Shahi extended from Kapisi to Gandhara, with a Turkic branch becoming independent in Zabulistan at one point. The Gandhara territory may have been bordering the Kashmir kingdom and the Kanauj kingdom to the east. The Turk Shahi capital of Gandhara, which possibly functioned as a winter capital alternating with the summer capital of Kabul, was Udabhandapura."The capital of the state of Kapisa–Gandhara (possibly, its winter capital) was Udabhandapura, now the settlement of Hund, situated on the right bank of the Kabul river. Most of the city was surrounded by a defensive rampart." in The Korean pilgrim Hui Chao, visiting the area in 723–729 CE, mentioned that these regions were ruled by Turk kings.

History

Establishment: Arab offensive and displacement of the Nezaks The last extant Nezak ruler Ghar-ilchi was recorded as the king of Jibin (former Kapisi/ Kabulistan) by the Tang dynasty in 653 CE. He was also likely to be the unnamed ruler who was confirmed as Governor of Jibin under the newly formed Chinese Anxi Protectorate in 661 CE and would broker a peace-treaty with the Arabs, the same year. Nonetheless, in 664–665 CE, Abd al-Rahman ibn Samura launched an expedition to reconquer the territories lost during the Caliphate Wars. Kabul was occupied in 665 CE after a siege of a few months but soon revolted, only to be reoccupied after another year-long siege. These events mortally weakened the Nezaks though their ruler — not named in sources — was spared upon converting to Islam.

Sometime soon (666/667?), the Nezaks were replaced by the Turk Shahis, first in Zabulistan and then in Kabulistan and Gandhara. Their ethnic identity remains unclear and the name might be a misnomer. According to Hyecho, who visited the region about 50 years after the events, the first Shahi ruler of Kapisi — named Barha Tegin by al-Biruni — was an usurper, who used to be a military commander in the service of the last Nezak King. Al-Biruni provides a rather legendary account of Barhategin's rise, extrapolating from multiple mythological motifs, and the precise circumstances surrounding the dawning of the Turk Shahis remain unclear.

Tang Protectorate and vassalage to the Tokhara Yabghus

The Turk Shahis, like the rest of the Western Turks, were nominally part of a protectorate under the Chinese Tang dynasty since circa 658 CE."China, at the other end of Central Asia, managed to bring the Western branch of the Qaγanate under Tang supremacy in 658 CE and consequently established a protectorate in Bactria which also extended south of the Hindukush." in The territory of the Turk Shahis was nominally partitioned into several Chinese Commanderies under administration of the Anxi Protectorate: the city of Yege (modern Mihtarlam) east of Kabul was considered as the seat of a Chinese Commandery for the Jibin country, and named the Xiuxian Commandery (修鮮都督府, Xiūxiān Dūdùfû), the city of Yan at the border with Gandhara was the seat of the Yuepan Commandery (悅般都督府, Yuèpān Dūdùfû), Ghazni was the seat of the Tiaozhi Commandery (條枝都督府, Tiáozhī Dūdùfû).

According to Chinese sources, in particular the chronicles of the Cefu Yuangui, the Turks in Kabul were vassals of the Yabghus of Tokharistan, who in turn swore allegiance to the Tangs. A young brother of the Tokhara Yabghu Pantu Nili — named Puluo (僕羅 púluó) in Chinese sources — visited the court of the Tang dynasty in Xi'an in 718 CE and gave an account of the military forces in the Tokharistan region, explaining that "two hundred and twelve kingdoms, governors and prefects" had been recognizing the authority of the Yabghus (specifically mentioning among them that "the king of Zabul rules two hundred thousand soldiers and horses, the king of Kabul two hundred thousand"), since the time of his grandfather, that is, probably since the time of their establishment.

Conflict with the Arabs

Under Barha Tegin, the Shahis mounted a counter-offensive and repulsed the Arab forces after Abd al-Rahman ibn Samura was replaced as Governor of Sistan c.665 CE, taking back lost territory as far as the region of Arachosia and Kandahar. The capital was shifted from Kapisa to Kabul. The Arabs attempted a counter-offensive when Rabi ibn Ziyad al-Harithi assumed the governorship of Sistan in 671 CE, attacking the Turkic "Rutbil" at Bost, and driving him to al-Rukhkhaj (Arachosia). Rabi's successor Ubayd Allah ibn Abi Bakra continued the war upon being appointed in 673 CE, leading Rutbil to negotiate a peace treaty for both Kabul and Zabul, in which the governor of Sistan acknowledged control of these territories by Rutbil and the King of Kabul. Little more is known about the rule of Barha Tegin, but many of the early Turk Shahi coins are attributed to him.

He was succeeded by his son Tegin Shah c. 680, whose regal title was "Khorasan Tegin Shah" meaning "Tegin, King of the East", probably referring to his resistance against the Umayyad caliph. His territory comprised the area from Kabulistan to Gandhara and initially included Zabulistan, which came to be ruled by Rutbil (Turkic: Iltäbär), his elder brother, who founded the dynasty of the Zunbils. Their relationship was at times antagonistic, but they fought together against Arab incursions.

The Arabs again failed to capture Kabul and Zabulistan in 683 CE: their general Abu Ubaida ibn Ziyad was imprisoned in Kabul and the governor of Sijistan Yazid ibn Ziyad was killed as he attacked the city. In 684–685, Kabul briefly comes under Arab control. In 698 Ubayd Allah ibn Abi Bakra of the Umayyad Caliphate lead an 'Army of Destruction' against the Zunbils, was defeated and was forced to offer a large tribute, give hostages including three of his sons and take an oath not to invade Zunbil again. About 700 Ibn al-Ash'ath tried again to invade with the 'Peacock Army', but after some initial progress eventually formed a peace treaty with the Turks, and turned around to lead a rebellion against the Umayyad viceroy of the east, al-Hajjaj ibn Yusuf.Hugh Kennedy, The Great Arab Conquests', 2007, pages 194-198

Tegin Shah apparently regained complete suzerainty over Zabulistan around 710 CE. This appears from the accounts in the Chinese chronicles, which relates that the rulers of Zabulistan "subjugated themselves to Jibin (Kabul)", sometime between 710 and 720 CE. During this period, it seems the Zunbils and the Turk Shahis intermittently accepted, or were forced to accept, payment of taxes to the Arabs, thereby acknowledging some form of political dependence, but resisted fiercely when the Arabs attempted to take a more direct military, political or religious control.

From 711 CE, the Turk Shahis also had to face a Muslim threat from the southeast, as the campaigns of Muhammad ibn Qasim established the Caliphal province of Sind, as far as Multan, at the gates of Punjab, which would last until 854 CE as an Umayyad and then Abbasid dependency.

Tang dynasty investiture In 719/20 CE, the Tegin of Kabulistan (Tegin Shah) and the Iltäbär of Zabulistan (here named "Shiquer") sent a combined embassy to Xuanzong, the Chinese Emperor of the Tang dynasty in Xi'an, to obtain confirmation of their thrones. The Chinese emperor signed an investiture decree, which was returned to the Turk rulers. The official Chinese recognition of the enthronement of Tegin Shah appears in the annals of the Tangshu:

The word "Geluodazhi" in this extract (Chinese: 葛罗达支, pronounced in Early Middle Chinese: kat-la-dat-tcǐe), is thought to be a transliteration of the ethnonym Khalaj. Hence Tegin Shah was described as "Tegin of the Khalaj". This title also appears on his coinage in Gupta script, where he is named "hitivira kharalāča", probably meaning "Iltäbär of the Khalaj".

In 720 CE, the ruler of Zabulistan (謝䫻, Xiėyù) also received the title Gedaluozhi Xielifa (Chinese: 葛達羅支頡利發), Xielifa being the known Chinese transcription of the Turkish "Iltäbär", hence "Iltäbär of the Khalaj".Original Chinese in Cefu Yuangui, book 0964 冊府元龜 (四庫全書本)/卷0964 "九月遣使冊葛達羅支頡利發誓屈爾為謝䫻國王葛達羅支特勒為𦋺賔國王", simplified Chinese "九月遣使册葛达罗支颉利发誓屈尔为谢䫻国王葛达罗支特勒为𦋺賔国王", "In September [720 CE] ambassadors recorded that Gedalouzhi Xielifa Shiquer was enthroned as king of Zabulistan, Gedaluozhi Tele was enthroned as king of Jibin." see also " 開元八年,天子冊葛達羅支頡利發誓屈爾為王。至天寶中數朝獻。" "In the eighth year of Kaiyuan (720), the Emperor approved the enthronement of Gedalouzhi Xielifa Shiquer. Their envoys came to the royal court several times until the Tianbao era (742–756)." in This appears in another extract from the Tangshu describing the country of Zabulistan (谢䫻, Xiėyù), mentioning how Zabulistan was a vassal to the Kabul Shah around the same period, and how the Zunbil ruler, named "Shiquer", was also recognized by the Chinese court:

These two Chinese accounts tend to confirm that the Turk Shahi and Zunbil rulers were Khalaj Turks. The Korean pilgrim Hyecho accompanied the return embassy in 726 CE, and wrote an account of his travel and visit at the court of Kabul, relating that Turk ("T’u-chüeh") kings ruled the territories of Gandhara, Kapisa and Zabulistan at the time, that they were Buddhists, and that the King of Kabul was the uncle of the ruler of Zabul."The definitive annexation of Tokharistan and Gandhara to the Western Türk Empire was to take place some years later, in c. 625, when Sasanian Iran became involved in the war against Byzantium that ultimately led to its eclipse." in

Victory over the Arabs

In 739 CE, Tegin abdicated in favour of his son Fromo Kesaro: