Kingdom of Heaven

In 1184 France, Balian, a blacksmith, is haunted by his wife's recent suicide. A Crusader passing through the village introduces himself as Balian's father, Baron Godfrey of Ibelin, and asks him to return with him to the Holy Land, but Balian declines. The town priest, Balian's half-brother, reveals that he ordered Balian's wife beheaded before burial, and Balian kills him in a fit of rage and flees the village.
Balian joins his father, hoping to gain forgiveness and redemption for himself and his wife in Jerusalem. Soldiers sent by the bishop arrive to arrest Balian, but Godfrey refuses to surrender him, and in the ensuing attack, Godfrey is struck by an arrow that breaks off in his body, fatally wounding him.
In Messina, Godfrey knights Balian and orders him to serve the King of Jerusalem and protect the helpless, then succumbs to his injuries. During Balian's journey to Jerusalem his ship runs aground in a storm, leaving Balian the only survivor. Balian is confronted by a Muslim cavalier, who attacks him over his horse. Balian reluctantly slays the cavalier but spares the man's servant, and the man tells Balian that his deed will gain him fame and respect among the Saracens.
Balian becomes acquainted with Jerusalem's political arena: the leper King Baldwin IV; Tiberias, the Marshal of Jerusalem; the King's sister, Princess Sibylla; and her husband Guy de Lusignan, who supports the anti-Muslim activities of brutal factions like the Knights Templar. After Baldwin's death, Guy intends to break the fragile truce with the sultan Saladin and make war on the Muslims.
Guy and his ally, the cruel Raynald of ChÃ¢tillon, attack a Saracen caravan, and Saladin advances on Raynald's castle Kerak in retaliation. At the request of the king, Balian defends the villagers, despite being overwhelmingly outnumbered. Captured, Balian encounters the servant he freed, who he learns is actually Saladin's chancellor Imad ad-Din. Imad ad-Din releases Balian in repayment of the earlier debt. Saladin arrives with his army to besiege Kerak, and Baldwin meets it with his. They negotiate a Muslim retreat, and Baldwin swears to punish Raynald, though the exertion of these events weakens him.
Baldwin asks Balian to marry Sibylla and take control of the army, knowing they have affection for each other, but Balian refuses because it will require Guy's execution. After Baldwin dies, Sibylla succeeds her brother, and Guy becomes king. Guy releases Raynald, asking him to give him a war, which Raynald does by murdering Saladin's sister. Sending the heads of Saladin's emissaries back to him, Guy declares war on the Saracens and sends assassins to kill Balian, though Balian survives the attempt.
Guy and the Templars march Jerusalem's army to war, despite Balian's advice to remain near water. Saladin's army annihilates the Crusaders in the ensuing desert battle, executes Raynald, and marches on Jerusalem. Tiberias and his men leave for Cyprus, believing Jerusalem lost, but Balian remains to protect the people in the city, knighting the men of the city. After a siege that lasts three days, a frustrated Saladin parleys with Balian. When Balian reaffirms that he will destroy the city before surrendering it, Saladin agrees to allow the Christians to leave safely in exchange for Jerusalemâthough he ponders if it would be better if there were nothing left to fight over.
Balian is confronted by the disgraced Guy one final time, but defeats and spares him. In the marching column of citizens, Balian finds Sibylla, who has renounced her claim as Queen. After they return to France, English knights en route to retake Jerusalem ride through the town to enlist Balian, now the famed defender of Jerusalem. Balian tells the crusader that he is merely a blacksmith again, and they depart. Balian is joined by Sibylla, and they pass by the grave of Balian's wife as they ride toward a new life together. An epilogue notes that "nearly a thousand years later, peace in the Holy Land still remains elusive."

Question: Who releases Balian in repayment of the earlier debt?
Answer: Imad ad-Din