The relational nexus between Muslim saint and Muslim ruler in medieval and early modern times was almost always a fraught one. Both saint and ruler laid claim to divinely invested authority, claims that could coexist, cooperate, and clash. A given saint might support a ruler, undermine him, or simply ignore him, while rulers moved between strategies of co-opting saints, seeking them out for their baraka and the social power that being connected to a saint might bring, endowing zawiyas, khaniqahs, and the like, even as some saintly shaykhs made a prominent point of rejecting both contact with and reception of wealth from rulers. Occasionally a Muslim claimant to sainthood ran seriously afoul of a ruler, resulting in exile, imprisonment, or even martyrdom.
I encountered the story- from the early thirteenth century Khawarezm domains- I’ve translated and presented below first in an Ottoman context, in the Ta’rîh (History) of Ibrâhîm Peçevî (d. c. 1650), an Ottoman official and author, who described the martyrdom of the Kurdish Şeyh Mahmûd of Diyarbakır, executed by Sultan Murad IV, probably because the sultan feared the saint, who had a vast following across the Kurdish lands, posed a political threat. Peçevî, who had been posted in Diyarbakır as a defterdâr, had been an intimate of the saint and was deeply sorrowed to learn of his martyrdom. Upon learning that Şeyh Mahmûd had died, he was reminded, he writes, of the story I’ve translated here. It comes from the massive Persian hagiographic compilation, Nafaḥāt al-uns, by the poet, sufi, and author Nūr al-Dīn ‘Abd al-Raḥmān Jāmī (d. 1492). There are indeed striking parallels, as well as differences: Majd al-Dīn, while clearly of saintly status, is seen here oversteping his limits in his relationship with the powerful and axial saint Najm al-Dīn al-Kubrā (d. 1221) in relating his vision, a vision that implies exalted spiritual status. The remainder of the story is largely self-explanatory, though I’ve included some notes for clarification here and there. Given both the odd details, the hints of court intrigue, and the spectacular ending- the Mongols totally devastated the Khawarezm lands- it would be a popular item in Jāmī’s hagiography. Peçevî reproduced, in Ottoman Turkish form, a condensed version of the story (and thereby implicitly criticized the by-then deceased Murad IV and warned future sultans) in his chronicle, while it was circulated in Ottoman Turkish in other contexts as well. The lessons are clear enough: rulers ought to observe proper care and respect around the saints, as the consequences of not doing so can be truly enormous!
One day Shaykh Majd al-Dīn [Baghdādī] was sitting with a group of dervishes when a state of spiritual intoxication came over him. He said: ‘I was a duck’s egg upon the shore of the sea, and Shaykh Najm al-Dīn [Kubrā] was a bird with his wings of spiritual instruction spread out above my head until I came forth from the egg and I was like the young of the duck, then went into the sea, while the shaykh remained on the shore.’
Shaykh Najm al-Dīn knew [what Majd al-Dīn said] by the light of divinely instilled power, and the words ‘He will go into the ocean!’ passed upon his tongue . When Shaykh Majd al-Dīn heard that he was fearful, and he came before Shaykh Sa’d al-Dīn Ḥamawī and with great humility asked, ‘When the time is right with the shaykh, will you give him report of me such that I may enter his presence and request forgiveness?’
When the shaykh underwent a pleasant state in the midst of semā’,  Shaykh Sa’d al-Dīn told him about Shaykh Majd al-Dīn, who then came, barefooted and with a basin filled with fire placed upon his head, and stood in the place where shoes are left. Shaykh [Najm al-Dīn] looked to him and said, ‘In accordance with the way of the dervishes you have desired forgiveness, your faith and your religion you will keep sound and whole, but your head will go away [ie you will die] and you will go into the sea. But we also will be in your head, and the heads of the commanders and the king of Khwarezm will be in your head and the world will become ruined.’ Shaykh Majd al-Dīn fell at the shaykh’s feet [to kiss them].
In only a little while the words of the shaykh were made manifest: Shaykh Majd al-Dīn preached in Khwarezm, and the mother of Sultan Muhammad, who was a woman of exceeding beauty, attended the preaching of Shaykh Majd al-Dīn, and would often go on pious visits to him. Slanderers sought occasion until one night the sultan was very drunk, and they claimed to him, ‘Your mother is going to end up entering the madhhab of Abū Ḥanīfa by marrying Shaykh Majd al-Dīn!’ The sultan became very angry and commanded that the shaykh be cast into the Tigris, so they cast him in.
The report came to Shaykh Najm al-Dīn, and he became very disturbed and said, ‘We are God’s and to God we return. They cast my son Majd al-Dīn into the water and he perished!’ He placed his head on his prayer rug and for a while was upon the prayer rug. Then he raised his head from the prayer rug and said, ‘From God Almighty I ask that the blood-price of my son incurred by Sultan Muhammad be answered!’ The sultan learned of this and became deeply repentant and came on foot to the presence of the shaykh, carrying a basin full of gold as well as a knife and winding-sheet [for burial] upon [the basin of gold]. Bareheaded he came and stood in the row of shoes and said, ‘If the blood-price is necessary, here is the gold, and if retribution, here is a knife!’
The shaykh answered, ‘That was written in the Book. His blood price is your entire kingdom, and your head too will go [you will die], along with most of your people, we too sharing in your fate.’ Sultan Muhammad returned, hopeless, and soon Ghengiz Khan came forth and did what he did.
Mawlana Abdulrahman bin Ahmed Jami and Mahdi Tawhidipur, Nafahat al-uns min hadarat al-quds (Tehran: Kitabfurushi-i Saadi, 1959).
 This utterance is somewhere between prophecy and threat- as indicated by Majd al-Dīn’s reaction.
 That is, the ritual of music and dance carried out by sufis, in various forms.