I'll begin in what's known as the Islamic Golden Age under Haroon. Haroon, while leader of the Abbasid Caliphate, brought his empire to unprecedented heights, but "he may have undermined its strength by over-taxation, the unvarying disease of old empires."* After he died in 809, his son Mamoon was able to wrest control. It was Mamoon who formally founded the House of Wisdom in Baghdad, which contributed greatly to advancements in mathematics and astronomy. But Mamoon also allowed Khurasan to become autonomous. Because of this, when Mutasim took over after Mamoon, he could no longer rely on army recruits from Khurasan as his predecessors had done. So he brought in slave boys from Turkestan. These turks would end up becoming the bulk of the empire's military. To quote Glubb again, "the Turks were mostly heathen, did not even trouble to learn Arabic, and were hated by the public." Mutasim would also move the capital to Samarra, a move that angered the Arabs in his empire as it suggested a preference on Mutasim's part for the Turks.
After Mutasim died, his son took over. He would rule for six years and die, and the next Kahlif would be Mutawakkil. Mutawakkil chose to remain at Samarra surrounded by his Turkish guards. His son, the heir-apparent, lost his title after messing around with a Greek concubine, but a high-ranking Turkish slave talked Muntasir into having his father murdered. Muntasir was then named Khalif. And so begins the disintegration of Arab hegemony and the rise of a Turkish military order. We would see the capital returned to Baghdad in 892, but by this time "the Arab Empire had virtually ceased to exist." The glue had had help the empire together was claimed descendence from the Prophet, but the population soon realized the khalif was now a mere front, and that Turks were exercising the real power, and so provinces began to fall away. Mutahdid took over in 892, but by this time he was only able to collect taxes from a small area in central Iraq, and simply lacked the funds to maintain a sufficient mercenary army.
An event that illustrates the severity of the rift between Arabs and Turks was the Carmathian rebellion. The Carmathians arose out of the Arabian peninsula, and were Shiites, yes, but their motive for rebellion was most likely anger at foreign influence in the empire, notably Turkish militarism. The khalifate did not seek to reconcile with these Arabs but labeled them enemies. Due to Turkish and Persian influence, the khailfate held no respect for Arab tribes anymore.
Fast-forwarding, we see the khalifate become ,at one point, a puppet of the Shiite Dailamites. The Abbasid Empire was effectively no more. Baghdad devolved into chaos and there were multiple coups de'etat. The khalif in Baghdad would become a principally religious figure. We also see the Byzantine Empire becoming much stronger around this time.
Fast-fast-forwarding, the founder of the Seljuk Empire was Tughril Beg. He was a grandson of Seljuk, and before establishing his empire, he was a chief of the Ghuzz. The Ghuzz "were a tribe of primitive Turkmans, who grazed on the steppes north of the Aral sea." Apparently "Their principle occupation was war and their killing weapon was a short bow, which they used on horseback at full gallop." Tughril Beg was Muslim, despite the fact that most of his tribesman were not, and also, the khalifate in Baghdad had by this time regained some respect as a religious institution. The khalifate had no army, however, and Tughril Beg moved into the palaces, while the Ghuzz "scattered over the fertile valley of Iraq, plundering and killing, and carrying off all the young women."
Tughril Beg dies in 1063, childless, still illiterate, the founder of an empire. He was succeeded by Alp Arslan, an energetic ruler who loved knowledge and diligent administration.
*A Short History of the Arab Peoples, by Sir John Glubb
tl;dr: Arabs come to rely on Turks in their military. Turks seize influence, undermining credibility of the khalifate. The khalifate was the glue of the empire, and so the empire begins to disintegrate. This disintegration coincides with a height in Byzantine power, which only contributes to an already chaotic power struggle/vacuum. A weakened Baghdad eventually falls to a Sunni Turk.