Under the Buyids and the Seljuqs it appeared that the Abbasid caliphate had been reduced to a mere spiritual and symbolic role. The caliphs were respected as religious leaders, but were politically side-lined. But they were not finished after all. Quarrels within the Seljuq family allowed them to reassert themselves - starting with the energetic al-Mustarshid (1118-1135) and continuing with al-Muqtafi (1136 - 1160). Al-Muqtafi recruited his own army of Greeks and Armenians (not Turks) - and on sultan Masu'd's death in 1152 extended the caliph's authority over much of Iraq, for the first time since the early 900s.
He was the first Caliph to get sole power over Iraq, to the exclusion of any sultan since the time when the Buyids first appeared. Ibn al-Athir
He took over the sultan's palace in Baghdad, encouraged the regional amirs who opposed the Seljuqs, and led his army to success in battle. Once again the Abbasids ruled - but only in Iraq.
Al-Nasir (1180 -1225) restored the Abbasid caliphate to centre-stage. He left the struggle against the Franj ("Crusaders") to the Kurdish Ayyubid dynasty, which under the leadership of Saladin had put an end to Fatimid rule in Egypt in 1171. In the east he tried to stem the advance of the Khwarazmian empire but his role as a religious leader was also significant. He tried to reconcile the various Islamic divisions, founding the Rahhasiyya order of which the Ayyubids, the Rum Seljuqs and the Ghurids became members - and even the Shi'i Ismailis, and, eventually, the Khwarazm shahs. More on Saladin here
By the time of sultan Masu'd's death in 1152, most of the Seljuq empire had disintegrated, leaving his successors no more than the province of Jibal (Hamadan and Isfahan). Sanjar ruled for a little longer independently as "king of the east" (until 1157). The title of Sultan continued to be conferred on various Seljuq descendants, until the last one, Toghrul III, was killed during an invasion by the Khwarazm shah Tekish in 1194.
The Khwarazmian empire (1077 - 1231)
The Khwarazm shah took advantage of Sanjar's death in 1157 to begin expanding into former Seljuq territory: in 1194 the Khwarazm Shah Tekish eliminated the last Seljuq sultan. His son, Muhammad II took on the Ghurids, Qarakhanids and Qarakhitay - with eventual success. The Abbasid caliph was forced to acknowledge his supremacy. From his capital at Gurganj (Urgench), by 1217 he dominated the Iranian plateau entirely (see the map above), as well as all Central Asia, Afghanistan and parts of India. Khwarazm was extremely wealthy, but its cultural life was a shadow only of former glories, as the ruler concentrated on military efficiency and ruthless control of the disparate - and heavily taxed - peoples of his empire. As an antidote to the harshness of the rule of the Khwarazm shah, the mystical version of Islam - Sufism - became increasingly popular. The extent of his rule masked its inherent weakness; he was unable to rely on the loyalty of his family, his army, or his religious officials (he was flirting with Shi'ism as a symbol of his enmity with the Abbasid caliph al-Nasir). And the Mongols were getting closer …
Illustration of "Conference of the Birds" (Mantiq-ut-Tayr) - from a 16th century folio. The story is by Attar of Nishapur, a 12th century Sufi. The hoopoe is adderessing the assembled birds (see here).