Afzaladdin Badil ibn Ali Nadjar Khāqāni (1121/1122, Shamakhi – 1190, Tabriz) was a Persian poet. He was born in the historical region known as Sharvan (located now in present country of Azerbaijan), under the Sharvanshah (a vassal of the Seljuq empire) and died in Tabriz, Iran. He was born into the family of a carpenter in Melgem, a village near Shamakhy. Khaqani lost his father at an early age and was brought up by his uncle, Kafi-eddin Umar Shervani, a doctor and astronomer at the Shirvanshah’s court, who for seven years (until his death) ####acted "both as nurse and tutor" to Khaghani. Khaqani's mother, originally of Nestorian faith, later accepted Islam. The poet himself had a remarkable knowledge of Christianity, and his poetry is profused with Christian imagery and symbols. He was also taught by his cousin (son of Kafi-eddin Umar) in philosophy. His master in poetry was the famous Abul-Ala Ganjavi who introduced him to the court of Khaqan Manuchehr Shirvanshah and Khaqani got his title from this king. He also married daughter of Abul-Ala.
In his youth, Khaghani wrote under the pen-name Haqai'qi ("Seeker"). After he had been invited to the court of the Sharvanshah Abu'l Muzaffar Khaqan-i-Akbar Manuchiher the son of Faridun, he assumed the pen-name of Khaqani ("regal"). The na'at (a poem in praise of Prophet Muhammad) written at the time when his literary talent had reached its peak, procured him the title Hassān'l-A'jam. Hassan ibn Thabit being a famous Arabic poet who composed panegyrics in praise of Prophet Muhammad, Khaqani's title is reference to the fact that he was the Persian Hassan. As well as Diwān, Khāqāni left some letters and a lesser known 'Ajaibu l-Gharyib (Curious Rarities). The life of a court poet palled on him, and he "fled from the iron cage where he felt like a bird with a broken wing" and set off a journey about the Middle East. His travels gave him material for his famous poem Tohfat-ul Iraqein (A Gift from the Two Iraqs), the two Iraqs being 'Persian Iraq' (western Iran) and 'Arabic Iraq' (Mesopotamia)). This book supplies us with a good deal of material for his biography and in which he described his impressions of the Middle East. He also wrote his famous qasida The Portals at Madain beautifully painting his sorrow and impression of the remains of Sassanid's Palace near Ctesiphon.
On return home, Khaqani broke off with the court of the Sharvanshah’s, and Shah Akhsitan gave order for his imprisonment. It was in prison that Khaqani wrote one of his most powerful anti-feudal poems called Habsiyye (Prison Poem). Upon release he moved with his family to Tabriz where fate dealt with him one tragic blow after another: first his young son died, then his daughter and then his wife. Khaqani composed moving elegies for all three most of which have survived and are included in his diwan (the book of his collected poems). Khagani was left all alone, and he soon too died in Tabriz. He was buried at the Poet’s Cemetery in Surkhab Neighbourhood of Tabriz. Khaqani left a remarkable Persian-language heritage which includes some magnificent odes-distiches of as many as three hundred lines with the same rhyme, melodious lyrics, dramatic poems protesting against oppression and glorifying reason and toil, and elegies lamenting the death of his children, his wife and his relatives. Some of the quatrains of Khaqani are also recorded in the book Nozhat al-Majales.