Ibn al-Khatib wrote this elegy for himself in prison in Fez in 776 AH (1374 CE). The Marinid sultan Abu al-Abbas Ahmad had arrested him to keep a condition set by Ibn al-Ahmar, the ruler of Granada, who was al-Ghani billah, the sultan Ibn al-Khatib had served as vizier; he was then tried for heresy. Ibn Khaldun, whom Ibn Hajar calls his friend, records that during his ordeal in prison he was “expecting the calamity of death” and composed these lines, and that men sent by his enemy Sulayman ibn Dawud then came to the prison at night and strangled him; al-Maqqari copied the account and the poem from Ibn Khaldun into Nafh al-Tib and Azhar al-Riyad. He speaks as a man already dead: a silent sermon, breath cut off, the great turned to bones and the feeder to food, suns set, swords and fortunes failing those who trusted them, a youth with chests of clothes carried to the grave in a rag; then he turns to his enemies: Ibn al-Khatib is gone, and only one who never dies has any right to rejoice. Ibn Hajar says it was widely believed he composed it as he was led to his death, but holds Ibn Khaldun's account, that he wrote it in prison, to be the correct one; and al-Maqqari saw in Fez a takhmis of it, which sets three new half-lines before each of its lines, attributed to one of the Banu al-Sabbagh, with extra lines that he thought resembled Ibn al-Khatib's own manner.