DOHA, Nov 30 (Reuters) -

Last week, as world leaders feted Qatar for brokering a truce between Israel and Hamas, its negotiators secretly doubled down on their mediation efforts, fearful the ceasefire would to collapse before it even started.

Working through the night, Qatari officials helped clinch the vital final details of a truce that ultimately lasted for seven days before hostilities resumed on Friday, permitting the release of dozens of hostages held in Gaza in exchange for hundreds of Palestinian prisoners, and the flow of humanitarian aid into the shattered coastal strip. Qatar said on Friday it was working with both sides to repair the deal.

Reuters has pieced together the most detailed account to date of how Qatar's mediators in Doha bridged the divide between Israel and Hamas on Nov. 22. It offers a glimpse of Qatar's muscular approach in talks between what one official involved in the negotiations called "two parties that have zero level of confidence in each other."

When the original truce agreement was unveiled last week, there were real fears it would never get off the ground, one of Qatar's lead negotiators, career diplomat Abdullah Al Sulaiti, said.

"I thought we were going to lose it and that the agreement wouldn't fly," he said in an interview. The deal covering the truce and accompanying prisoner and hostage exchanges had been loosely worded.

The tiny Gulf state's negotiators knew Israel and Hamas had yet to agree on when, or how, the ceasefire and the swap would begin, according to sources in Qatar, the Palestinian Territories and Egypt familiar with the high-stakes talks.

It was necessary to clarify all the points in the agreement and make sure they meant the same thing to Israel and Hamas, a source briefed on the negotiations said.

For example, the Israeli side had pledged to "park" tanks it was using inside the Gaza strip, but nobody had agreed on what that meant on the ground, said the source, who asked not to be named because of the sensitive nature of the talks.

To remain focused, Qatari Prime Minister Sheikh Mohammed bin Abdulrahman Al Thani cleared his agenda, cancelling planned trips to Moscow and London, the source briefed on the negotiations said.

Inside one of his Doha offices on the afternoon of Wednesday, Nov. 22, Sheikh Mohammed kicked off a new round of negotiations just hours after the truce had been unveiled, the source said.

In the prime minister's main meeting were the Mossad chief, David Barnea, who had flown in from Israel for at least the third time since the beginning of the war, and a delegation of Egyptian intelligence officers. The Qataris used a separate room to call Hamas delegates who had remained in their villa office across town, the source said.

Instead of simply passing on messages from one side to the other, the Qataris' approach to mediation was to be proactive and throw their weight into negotiations, according to a U.S. official familiar with the matter and Egyptian security sources.

Doha had already used such tactics to push for solutions to close the gaps in demands between Israel and Hamas, notably when negotiators tackled the sensitive issue of hostages ahead of the first truce announcement, the U.S. official said.

The U.S. Department of State and the Hamas political office in Doha did not respond to detailed questions for this article. The office of Israeli Prime Minister Benjamin Netanyahu, which oversees Mossad, declined to comment.

Qatar's foreign ministry told reporters that Hamas and Israel negotiated in Doha until "the early morning" of Nov. 23 and agreed on a plan to implement the truce deal the next day. It did not respond to a request for comment for this story.

NOT "POSTMEN"

At the start of the negotiations, the Netanyahu administration had said it would not swap Palestinian prisoners held in Israel for hostages held in Gaza. Hamas, which in 2011 had obtained the liberation of more than 1,000 Palestinian prisoners detained in Israel in exchange for the release of one Israeli soldier, made high demands, people familiar with the negotiations said.

The two sides eventually agreed on a ratio of three Palestinian prisoners for each civilian hostage.

The key, the Qatari official involved in the negotiations said, was to amend what was being proposed by one side until it became acceptable by the other.

"We say 'Listen, let's have a second round of discussions with you before we send the proposal,'" he said, speaking on the condition of anonymity.

"If we decided to be like postmen and deliver letters only, I doubt that we would have finished this agreement."

On Nov. 22, Qatari emissaries worked the phones and moved back and forth between different rooms, the source briefed on the negotiations said.

Qatari negotiators shepherded Israel and Hamas to agree on exactly where in Gaza Israeli tanks would be stationed during the truce. Similarly, they brokered an agreement on how Israeli soldiers would meet a Hamas demand to vacate Gaza hospitals, including Al Shifa, where they had taken positions, the source said.

The negotiators, some of whom have been involved in Israel-Hamas mediations since 2014, also needed to work out a crucial element: a safeguard mechanism designed to ensure that any small breach in the ceasefire would not cause it to collapse, he said.

They managed to get both sides to sign off on specific procedures they would have to follow in the event of an incident, reviewing detailed scenarios such as gunfire or tank movements, he said.

The mechanism was activated shortly after the truce came into force, when Israeli soldiers opened fire on Palestinians trying to move to northern Gaza, the source said.

About five hours into the meeting, Qatar's Emir Sheikh Tamim bin Hamad Al Thani spoke on the phone with U.S. President Joe Biden and discussed the deal's implementation, according to the White House readout of the call.

After the marathon session was over some hours later, Qatar's foreign ministry announced the truce would come into force on Friday, Nov. 24 at 7 a.m. in Gaza.

GO-TO MEDIATOR

As one of the very few countries with an open line of communication to both Israel and Hamas, gas-rich Qatar has emerged as the lead go-to negotiator in the weeks-long war that began with Hamas attack on Oct. 7. In addition to the U.S., Russia has also praised the role of its "Qatari friends."

Qatar's mediation has also elicited criticism in the West, with some U.S. and European politicians accusing the Gulf state of supporting a group, Hamas, they regard as a terrorist organization.

The ambivalence was on full display when Sheikh Tamim landed in Berlin last month: "State visit by the blood emir," said an Oct. 12 banner headline on German newspaper Bild.

Qatari officials say they began hosting Hamas representatives in Doha in 2012 at Washington's request, when the Palestinian militants' political office was ousted from Syria. Israel vets all financial transfers Qatar makes to Palestinians in Gaza, Qatari sources have said.

Qatar's personal connection to the militant group's key figures is perhaps the most important factor behind Qatar's ability to effectively negotiate in this conflict, said Mehran Kamrava, professor of government at Georgetown University in Qatar.

"They say, 'Look. We've provided an office and logistical support at tremendous reputational cost…We were the only ones who were there for you when you needed us and now is the time when you need to return the favour,'" he said.

Despite proximity to Hamas officials, Qatari negotiators did not speak directly to the group's leaders in Gaza, but through its representatives based in Doha. The communication chain broke several times, at one point for two full consecutive days, during the month and a half of intense fighting that preceded the Nov. 24 truce, because of power outage or Israeli shutdown, the source briefed on the talks said.

Mossad often plays a diplomatic role in Israel's dealings with Qatar, because the two countries do not have formal diplomatic relations, a situation that one Western source in the Gulf said also slowed the process.

Netanyahu has sworn to annihilate Hamas, which rules Gaza, in response to the Oct. 7 rampage by the militant group, when Israel says gunmen killed 1,200 people and took 240 hostages.

In response, Israel bombarded the territory for seven weeks and killed more than 15,000 Palestinians, according to health authorities in the coastal strip.

Since the pause in fighting began, around 100 hostages have been released from Gaza, including non-Israelis. Israel has released at least 210 Palestinians from its jails and allowed relief organizations to increase shipments of humanitarian aid and fuel to Gaza.

Speaking to Reuters days after the ceasefire started, Al Sulaiti, the Qatari mediator, said his work was far from over.

"At the beginning I thought achieving an agreement would be the most difficult step," said the civil servant who has been involved in Israel-Hamas mediations since 2014. "I've discovered that sustaining the agreement itself is equally challenging."

The truce lasted almost exactly a week. Hostilities resumed on Friday after Israel accused Hamas of firing rockets and reneging on a deal to free all women held as hostages.

(Additional reporting by Ahmed Mohamed Hassan in Cairo, Matt S. Spetalnick in Washington and Dan Williams in Jerusalem; Writing by David Gauthier-Villars; Editing by Frank Jack Daniel.)