The Arab Empire is the collective name for the three dynasties established by the Arabs in the Middle East in the Middle Ages, which are the Umayyad dynasty, the Abbasid dynasty and the Fatimid dynasty, of which the Abbasid dynasty has the longest existence, so the arab empire is sometimes referred to only by the Abbasid dynasty. In the middle of the Abbasid dynasty, the "Ghulam" system of slave legions began to rise, and the Ghulam Guards were the predecessors of the Mamluk legions, which also laid the groundwork for the decline of the Abbasid dynasty.

Soldiers holding Abbasid flags
In the early days of the Abbasid dynasty, there was a problem that the imperial army was a foreign soldier, and the Abbasid dynasty was founded by the Khorasan legion of the Abu Muslims, whose main members were mostly Persians from the Khorasan region. In 755 AD, after the Abu Muslims were killed by the Caliph Al-Mansur for their meritorious service, the Khorasan Legion launched an uprising to avenge the Abu Muslims, but it was soon suppressed, while the remaining Khorasan soldiers continued to serve the Caliph and became the main military force of the Abbasid dynasty.
The Ghulam system can be traced back to the seventh Abbasid caliph, Mamun, who still did not establish a legion with the Arabs as the main force. In order to balance the increasingly powerful Khorasan legion, Mamun decided to build a guard composed of Central Asian Turks to counter the Khorasan army, but this guard was not large, and the scheming Mamun also had an eye, and he guaranteed the loyalty of this guard by making all the upper officers of this guard Arab or Persian.
The Khorasan Legion of the early Abbasid dynasty
In August 833, Mamun died of illness, and his younger brother Mutasim became the new ruler of the empire, Andasim had a somewhat peculiar origin, his mother being a Turkic slave girl from Central Asia. It was because of this special status that Mu'ataisuimu was very close to the Turks, and after he ascended the throne, he found that the Khorasan legions were increasingly sitting in congress as a threat to the Abbasid dynasty, so Mu'ataisuim bought four thousand slaves from his mother's hometown, and then used these four thousand slaves to form a Ghulam guard to defend the caliphate's safety.
When he saw the Ghulam Guards fighting, Mu'ataisim began to massively expand its troops, making the Ghulam Guards evolve from a guard dedicated to protecting the caliph to the backbone of the imperial army.
The rise of the Ghulam system did weaken the Khorasan legions, but it also brought greater crises to the empire, and Mu'ataisim restrained the tiger-like Khorasans and introduced the wolf-like Turks into the Arab Empire.
Ghulam Guards
Moreover, while introducing Turkic soldiers, Mu'ataisim did not think of preventing the Ghulam Guards from growing bigger, and he abandoned his brother Mamun's practice and appointed talented Turks to become officers of the Ghulam Guards, resulting in no Arab presence in the Ghulam Guards from top to bottom.
Although the Ghulam Guards were ostensibly loyal to the caliph, the low-ranking soldiers were more loyal to their Turkic chiefs and increasingly unkind to the Arab ministers in the court.
Not long after the Ghulam guards lived in the capital of the Abbasid dynasty, they clashed with the local population, and these arrogant soldiers rode their horses all day long to run amok in the streets, and the people would be beaten by the Ghulam soldiers if they disobeyed. The behavior of the Ghulam Guards soon caused riots in baghdad, and people took to the streets to protest the atrocities of the Ghulam Guards, and in order to quell the riots, Mu'ataisui built the new capital samara city in northern Baghdad, and moved all the Ghulam guards into samara.
Samara City
Although the move of the Ghulam Guards into Samara appeased the grievances of the inhabitants of Baghdad, when Mu'ataisim entered Samara with his concubines and ministers, he found himself as if he had become a prisoner in the new capital, surrounded by Ghulam soldiers. Later, when Mu'ataisim led an expedition to the Byzantine Empire, Afsin, a Ghulam officer in Samara, raised an army to rebel, and Mu'ataisim hurriedly led his army back to his division and executed Afsin after quelling the rebellion.
At this time, Mu'ataisim was aware of the crisis from the Ghulam Guards, but before he could reorganize the Guards, he died of illness. After the death of Mu'ataisim, he was succeeded by his son Wasig,
The new ruler did not learn from his father's lesson, and Wasig still appointed a Turk named Asnas as the commander of the Ghulam Guard, resulting in assus became the true ruler of the empire after Wasig's death in 847 AD.
Ghulam cavalry
Vasig's death marked the official rise of the Ghulam Guards, and from then on the Caliph could no longer control the elite Ghulam Guards, and the Abbasid dynasty began to collapse, and there was no longer a male lord who could control the power of the state. And the Ghulam officers also began to constantly interfere in the Abbasid succession, and they still felt dissatisfied after changing one caliph after another, and later even three caliphs were ordered to be executed by the Ghulam guard captain.
It is said that three other caliphs were blinded by the Ghulam guards and expelled from the palace and became beggars on the streets of Baghdad.
During that period, the Ghulam Guards also "exchanged blood" for the Abbasid royal family, and almost all the caliphs married Turkic slave girls, and these Turkic concubines colluded with Ghulam soldiers to intervene in the abbasid state affairs.
The Baiyi Dynasty Army
While the Ghulam guards disrupted the Abbasid court, the Persians established the Samanid dynasty in the Abbasid Iranian plateau and Central Asia, and in western Iran, a state called the Baiyi dynasty began to rise, and they besieged Baghdad in 945 AD, the Ghulam guards in the city abandoned the city and fled, and the caliph became a puppet of the Baiyi dynasty.
Although the Ghulam Guards were expelled from Baghdad by the Baiyi Dynasty, their power was still not eliminated, and the Samanid Dynasty also followed the abbasid dynasty and established the Ghulam Guards.
The end of the Samanid dynasty was very similar to that of the Abbasid dynasty, and the increasingly large Ghulam guards began to become independent as the Ghaznavid dynasty, and in 999 AD the Samanid dynasty was destroyed.
The army of the Seljuk Empire
The fall of the Samanid Empire opened the eastern gateway of the Abbasid dynasty, and in 1055 AD, the Seljuks, who also had the background of Ghulam, attacked Baghdad, and after destroying the army of the Baiyi dynasty, the leader of the Seljuks, Tukruk, announced the establishment of the Seljuk Empire. By this time, the caliph had already died in name only, becoming a puppet of the Seljuks, until 1258 AD, when the Mongol Western Expedition led by Hulagu attacked Baghdad, the last caliph, Mustai Suimu, was killed, and the Abbasid dynasty was declared extinct.
Strictly speaking, the Abbasid dynasty had already perished after the rise of the Ghulam Guards, and the caliphs were puppets of the Ghulam governors and had no authority to speak of.
If the rise of the Ghulam Guards marked the decline of the Abbasid dynasty, Hulagu's Mongol cavalry broke through the last vestiges of the Abbasid dynasty.
References: History of the Arab Empire, The Complete History of Asir