Ghilman were introduced to the Abbasid Caliphate during the reign of al-Mu'tasim (r. 833-842), who showed them great favor and relied upon them for his personal guard. The ghilman were slave-soldiers taken as prisoners of war from conquered regions or frontier zones, especially from among the Turkic people of Central Asia and the Caucasian peoples (Turkish: Kölemen). They fought in bands, and demanded high pay for their services. They were opposed by the native Arab population, and riots against the ghilman in Baghdad in 836 forced Mu'tasim to relocate his capital to Samarra. The ghilman rose rapidly in power and influence, and under the weak rulers that followed Mu'tasim, they became king-makers: they revolted several times during the so-called "Anarchy at Samarra" in the 860s and killed four caliphs. Eventually, starting with Ahmad ibn Tulun in Egypt, some of them became autonomous rulers and established dynasties of their own, leading to the dissolution of the Abbasid Caliphate by the mid-10th century.
A ghulam was trained and educated at his master's expense and could earn his freedom through his dedicated service. Ghilman were required to marry Turkic slave-women, who were chosen for them by their masters. Some ghilman seem to have lived celibate lives. The absence of family life and offspring was possibly one of the reasons why ghilman, even when attaining power, generally failed to start dynasties or proclaim their independence. The only exception to this was the Ghaznavid dynasty of Afghanistan.