The release of the first of five British hostages kidnapped in Baghdad two years ago may be imminent after the US military freed a senior Shia militia leader from prison.

The freeing of Laith al-Khazali, an important member of Asaib al-Haq, an Iranian-backed militia group, marks a crucial breakthrough in efforts to secure the return of Peter Moore, a computer expert, and four British security men seized with him.

The kidnappers have demanded the release of Qais al-Khazali, the leader of Asaib al-Haq, along with his brother Laith and other militants, in return for the five Britons who were captured while working in the Iraqi Finance Ministry in a highly organised raid on 29 May 2007 by men dressed as Iraqi policemen.

Download the new Independent Premium app Sharing the full story, not just the headlines

A senior Iraqi politician in Baghdad said that he expected Qais al-Khazali, the most important of the Iraqis whose release is demanded by the kidnappers, to be handed over by US military forces to the Iraqi government in the next five days. It would then free him, opening the way for further releases of the British hostages.

The difficulty in arranging for the Britons to be released is that the Iraqis held by the US were accused of masterminding a devastating attack on a US base in the city of Kerbala early in 2007 in which five American soldiers were killed. When the Khazali brothers were arrested in Basra in March 2007 the US said they had a document containing detailed military information about the Kerbala camp.

A further problem is that the Iraqi government, Britain and the US do not want to be seen to be releasing prisoners in exchange for hostages. But a solution appears to have been found by Asaib al-Haq promising the Iraqi government that it would renounce violence and join the political process. This enabled the Iraqi government to say that the group could not do so while it held hostages, but it also suggested to the US that Asaib al-Haq could not be expected to cease armed actions while its leaders were being held in prison.

The attack at Kerbala, which was more expertly planned than most such incidents in Iraq, was part of a tit-for-tat covert war in Iraq between the US and Iran, sometimes waged through their proxies. This conflict was particularly intense in the first half of 2007, when five Iranian diplomatic officials were seized in a US helicopter raid on Arbil, the Kurdish capital, and, on 23 March in the same year, when 15 British Marines and naval personnel were captured by Iranian Revolutionary Guards in disputed waters in the Gulf.

Qais al-Khazali was part of the movement of the Shia anti-American cleric Muqtada al-Sadr following the US invasion in 2003. During the siege of the Sadrists by the US Marines in 2004 Qais was their chief spokesman. Both brothers later split from the Sadrists and Qais became the leader of an Iranian-supported special group called Asaib al-Haq (the Leagues of Righteousness). These groups were alleged to be armed, trained and paid by the Iranians in 2006-07 and were thought to specialise in attacking US forces.

It was two months after the Khazali brothers had been captured that men in Iraqi police uniforms stormed the Finance Ministry. They appeared to have exact information on what foreigners were employed there. They found Mr Moore, who was working for BearingPoint, a US management consultancy, and grabbed him along with two of his guards, but failed to kidnap a second consultant who hid among a group of Iraqis. Before the kidnappers left, they took away two other British guards working for the same Canadian security company, GardaWorld. Little is known of the security men except that two, Alec and Jason, are Welsh and two others, Alan and another man, also called Jason, are Scottish.

At least four videos of the five Britons have since been released by the captors, the most recent in March this year to the British embassy in Baghdad. Previously the videos had been given to the Arab media. Gordon Brown described one of the videos, which said that one of the hostages called Jason had committed suicide, as "a very distressing development".

Mr Moore's father, Graeme, said last night he was optimistic that he might soon see his son following the freeing of Laith al-Khazali but was not taking anything for granted. "This is obviously very exciting news," he said. "We have always been told that Peter may be the first one to be released. I heard this afternoon that this may take place within two days. The problem is that we have heard on several occasions in the past that a deal had been done and my son and the others were going to be freed but then this never happened."

The war in Iraq has seen repeated kidnappings – the vast majority of the victims have been Iraqis and the motive has generally been money. Kidnapping foreigners by Sunni insurgents was generally also for money, and the French and Italian governments are known to have paid large sums. The five Britons, grim though their captivity may be, may be fortunate they were kidnapped by the Shia who, unlike the Sunni, generally keep their victims alive.