The peaceful penetration of Turks into the originally Iranian lands of Central Asia, sc. into Transoxiana, Farghana and Khwarazm, and across the Dihistan Steppe (the modern Qara Qum Desert) towards the Caspian coastlands, had, however, begun several centuries before. The Iranian rulers of Soghdia who opposed the Arab invaders of the 1st/7th and early 2nd/8th centuries received assistance from the Western Turks, before the steppe empire of these Turgesh itself disintegrated. In addition to this, the Soghdian princes hired Turks from the steppes as mercenary soldiers and as frontier guards, thus anticipating the 'Abbasid caliphs' employment of Turkish slaves in their armies. In what was, before the rise of the Samanids, a politically fragmented region, with the independent political unit often little more than the city-state or petty principality, there was frequent internecine warfare and consequent employment for these warriors.
The Samanid amirate in Transoxiana and Khurasan meant that there was a strong barrier in the northeast against mass incursions from the steppes into the civilized zone. The Iranian world was now protected by a vigorous power, whose central government in Bukhara, had an advanced bureaucracy, utilizing techniques evolved in the 'Abbasid caliphate, and a well-disciplined professional army. Again, this army followed the 'Abbasid pattern in that it had a core of Turkish slave guards personally attached to the amir. Hence during the heyday of the Samanids - up to the middle of the 4th/1oth century - the frontiers of Transoxiana were held firm against pressure from the Turks outside. Such frontier regions as Isfijab, Shash and Farghana were protected by chains of ribats or fortified points garrisoned by ghazis or fighters for the faith. The amirs personally undertook punitive campaigns into the steppes when need arose, such as the great expedition to Talas in 280/893 of Isma'il b. Ahmad, when the capital of the Qarluq Turks was sacked and an immense booty of slaves and beasts taken. Similarly, the Afrighid Khwarazm-Shahs in the 4th/ioth century led an expedition each autumn into the steppes, the so-called Faghburiyya or "King's expedition".
During this period of Samanid florescence, large numbers of individual Turks were brought through Transoxiana into the Islamic world; the greater part of them found employment as military guards in the service of the caliphs and of provincial Arab and Persian governors. During the course of the 3rd/9th century the military basis of the 'Abbasid caliphate was completely transformed. Instead of relying on their Khurasanian guards, or on the remnants of an even earlier system, that of the militia of Arab warriors, the caliphs came to depend almost wholly on slave troops. These included such varied races as Arabs, Berbers, black Sudanese, Balkan Slavs, Greeks, Armenians and Iranians, but Turks from Central Asia were the most prominent of all. Much of the economic prosperity of the Samanid state was built on the slave trade across its territories, for the demand for Turkish slaves was insatiable; the Samanid government controlled the export of slaves across the Oxus, exacting tolls and requiring licences for the transit of slave boys. The Turks were prized above all other races for their bravery, hardihood and equestrian skill, and provincial governors and ambitious military commanders emulated the caliphs in recruiting for themselves bodyguards of these ghuldms. It was the existence of these professional troops which enabled such governors as Ahmad b. Tuliin and then Muhammad b. Tughi to throw off direct caliphal control in Egypt.