As so often in Byzantine history, a population movement which came to threaten the empire had its origins far beyond its borders. In the mid-sixth century the great Eurasian steppes were occupied by a new people, who spoke Turkic and called themselves Turks, or more precisely K¨ok Turks (‘Blue or Celestial Turks’). They established a Turkic khaganate sometime between 546 and 552 and apart from a short interruption in the later seventh century, this continued in existence until 744/5, when the Uighurs killed the last Turk khagan, Pai-mei, and sent his head to the Chinese court. The Turkic khaganate became the breeding-ground for other powerful Turkic tribal confederations. The most notorious were the Uighurs, who established their own khaganate over the remnants of the K¨ok Turk empire from 745 to 840, and, further west, the Qarluqs and the Oghuz. Like the Uighurs, the Qarluqs rebelled against their K¨ok Turk masters in 744/5. They then migrated west from near the headwaters of the Irtysh to the lands between Lake Balkhash and Lake Issyk-Kul. To the north and west of them, in the steppes between the Jaxartes and the Aral Sea, were the pastures of the Oghuz tribes, who were likewise former members of the Turkic khaganate. Their ruler bore the title of yabghu and was based at Yenikent. The Arabs and the Muslim successor states in Central Asia at first managed to maintain their defences against these nomadic peoples along the Jaxartes river. The Samanids (875–1005), the last Iranian dynasty in Central Asia, built a formidable line of fortresses in Fergana and Shash. The Islamisation of the Turkic peoples along the Jaxartes resulted from their close ties with the Muslims of Transoxiana.3 But in 999 this period of stability ended. The Qarakhanids, who belonged to the Qarluq confederation, concluded an alliance with Sultan Mahmud of Ghazna (998–1030) and destroyed the Samanids. The victors divided the spoils:Mahmud took Transoxiana, Khorasan and all the territories to the west of the Oxus, including Khwarizm. The Qarakhanids became masters of Sogdiana, Fergana, Bukhara, Samarkand and the lands to the east of the Oxus. The Iranian barrier in Central Asia had now collapsed, opening up the central Muslim lands to the Turkish hordes. The instability in Central Asia had serious repercussions for Armenia, Arran and al-Jazira, all close to the Byzantine borders. Because the central Iranian plateau – and notably the Dasht-i Kavir (Great Kavir), the greatest salt desert in the world – prevented any migration en masse to the south, the nomads took the easier route westwards, along the Caspian’s southern shore to the rich pastures of Azerbaijan and the plain ofMughan (see above, p. 132). A horde which had recently moved from Central Asia attacked Sennacherim-John Artsruni’s kingdom. The Armenians lost the battle, which probably took place either in 1016 or early 1017;4 and Sennacherim-John exchanged his kingdom for safer lands in the depths of AsiaMinor, under the protection of the emperor. Subsequent events only served to confirm the king’s wisdom: in 1021 a new horde of Turks devastated the country of Nig, between Shirak and Lake Sevan. Such were the first signs of the new enemy-to-come.