Khāqāni or Khāghāni (Persian: خاقانی) (1121/1122, Shamakhi, Shirwan – 1190, Tabriz), was a Persian poet. He was born in the historical region known as Shirvan (eastern part of today Azerbaijan), under the Shirvanshah (a vassal of the Seljuq empire) and died in Tabriz, Iran.
Khaqani (real name, Afzaladdin Badil (Ibrahim) ibn Ali Nadjar) was born into the family of a carpenter in 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 pen-name 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 Shirvanshah 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 (The Persian Hassān)(حسان العجم). 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 (in Persian: تحفه العراقين meaning 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 (in Persian: ايوان مداين) 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 Shirvanshah’s, and Shah Akhsitan gave order for his imprisonment. It was in prison at Şabran 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. 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 ghazals, dramatic poems protesting against oppression and glorifying reason and toil, and elegies lamenting the death of his children, his wife and his relatives.
According to Jan Rypka:
"A Master of the language, a poet possessing both intellect and heart, who fled from the outer world to the inner world, a personality who did not conform to type - all this places him in the front ranks of Persian literature."
Some of the quatrains of Khaqani are also recorded in the book Nozhat al-Majales.