Doha has a history of reaching out to all kinds of controversial groups, from rebels in Sudan's Darfur region to the Taliban in Afghanistan and Hamas in Gaza. Qatar touts itself as a neutral player that can act as an intermediary in regional conflicts. But its critics, notably Saudi Arabia and the UAE, allege it also uses such interventions to play both sides and fund radical Islamist groups, most recently in Libya and Syria. And to Doha's critics, the hostage deal was further evidence of that role.

"If you want to know how Qatar funds jihadis, look no further than the hostage deal," said a Syrian opposition figure who has worked with an al-Qaeda mediator on hostage swaps in Syria. "And this isn't the first — it is one of a series since the beginning of the war."

The FT spoke to people involved on both sides of the hostage swap deal, including two government officials in the region, three Iraqi Shia militia leaders and two Syrian opposition figures.

Around $700m was paid both to Iranian figures and the regional Shia militias they support, according to regional government officials. They added that $200m to $300m went to Islamist groups in Syria, most of that to Tahrir al-Sham, a group with links to al-Qaeda.

Those who spoke to the FT said the deal highlighted how Qatar has allegedly used hostage payments to bankroll jihadis in Syria. But to its Gulf neighbours, the biggest issue is likely to be the fact that Doha could have paid off their main regional rival, Iran, which they accuse of fuelling conflicts in the Arab world.

This particular saga began when an Iranian-backed Iraqi Shia militia, known as Kata'eb Hizbollah, kidnapped the Qataris in December 2015. Three Iraqi militia leaders say the hostages were held in Iran.

Kata'eb Hizbollah is an Iraqi group but it is seen as having links with Iran's main regional proxy, Hizbollah, the Lebanese militant group. The latter is helping Iran back Bashar al-Assad, the Syrian president, in his country's six-year conflict.

Two regional diplomats said they believed one of the Iraqi group's motives for the kidnapping was to give Hizbollah and Iran leverage to negotiate the release of Shia fighters kidnapped by the radical Sunni group Tahrir al-Sham in Syria.

Tahrir al-Sham, in previous iterations, was an al-Qaeda branch. It claims it has broken the connection, but the international community still views it as an affiliate.

The hostage transaction was also linked to a separate agreement to facilitate the evacuation of four towns in Syria — two surrounded by jihadi forces and two besieged by Shia militias — say Syrian rebels and diplomats.

One western diplomat said the arrangement provided Qatar the "cover" to finance the hostage deal. "Iran and Qatar had long been looking for a cover to do this [hostage] deal, and they finally found it," he said.

According to two opposition figures with close contact with the groups paid, Qatar used the evacuation arrangement to pay $120-$140m to Tahrir al-Sham. Another $80m, they said, went to the Islamist group Ahrar al-Sham.

"The Qataris pay anyone and everyone, to what end? They have only brought about our ruin," said a Syrian rebel commander, who gave details about the payments but asked not to be identified.

A regional Arab official said the total paid to jihadi groups was closer to $300m.

"So, if you add that up to the other $700m they paid to Iran and its proxies, that means Qatar actually spent about a billion dollars on this crazy deal," he said.

The Iraqi Shia militia commanders in Iraq, all from hardline Iranian-backed groups, said that, to their knowledge, Iran had obtained around $400m after giving them a payment they would not disclose. They agreed to share some details because they were unhappy about their share of the payment.

"They [the Iranians] took the lion's share," said a member of one of the Iranian-backed Shia militias in Iraq. "That's caused some of us to be frustrated, because that was not the deal."

Another confusing chapter of the deal is that Haidar al-Abadi, Iraqi prime minister, said in April his government had seized hundreds of millions of dollars, which Iraqi officials said arrived on Qatari planes "illegally". It is not clear if this is money is part of the sums mentioned above, or an additional amount.

"The money all came in suitcases, can you imagine this?" said one senior official.

Additional reporting by Simeon Kerr in Dubai

Watch: Why Saudi Arabia is mad at Qatar