WASHINGTON: Shortly after Hamas took hostages during their deadly assault on southern Israel on Oct. 7, the government of Qatar contacted the White House with a request: Form a small team of advisers to help work to get the captives freed.

That work, begun in the days after the hostages were taken, finally bore fruit with the announcement of a prisoner swap deal mediated by Qatar and Egypt and agreed by Israel, Hamas and the United States.

The secretive effort included tense personal diplomatic engagement by U.S. President Joe Biden, who held a number of urgent conversations with emir of Qatar and Israeli Prime Minister Benjamin Netanyahu in the weeks leading up to the deal.

It also involved hours of painstaking negotiations including Secretary of State Antony Blinken, CIA Director Bill Burns, national security adviser Jake Sullivan and his deputy Jon Finer, and U.S. Middle East envoy Brett McGurk, among others.

Two officials involved in the effort provided extensive details of the work that led to an agreement in which 50 hostages are to be freed in exchange for 150 Palestinian prisoners during a four-day pause in fighting.

Shortly after Oct. 7, Qatar - a long-established mediator in a volatile region - approached the White House with sensitive information regarding the hostages and the potential for their release, the officials said. The Qataris asked that a small team, which they called a "cell," be established to work the issue privately with the Israelis.

Sullivan directed McGurk and another National Security Council official, Josh Geltzer, to establish the team. This was done without telling other relevant U.S. agencies because Qatar and Israel demanded extreme secrecy with only a few people to be in the know, the officials said.

McGurk, a seasoned diplomat with deep experience in the Middle East, held daily morning calls with the prime minister of Qatar, Mohammed bin Abdulrahman bin Jassim Al Thani. He reported back to Sullivan and Biden was briefed daily on the process.

Biden got an upfront look at what the victims of the Hamas attack endured when he held an emotional, lengthy meeting on Oct. 13 with the families of Americans who were either being held hostage or were unaccounted for.

Days later, Biden traveled to Tel Aviv for Oct. 18 talks with Netanyahu. The official said securing the release of hostages was a central focus of his discussions with Netanyahu and his war cabinet, as well as humanitarian assistance.

Five days later, on Oct. 23, the White House team's work helped yield the release of two American hostages, Natalie and Judith Raanan.

From outside Sullivan’s West Wing office McGurk, Sullivan and Finer tracked in real time the captives' difficult, multi-hour journey out of Gaza.

The return of the two Americans proved it was possible to gain freedom for hostages and gave confidence to Biden that Qatar could deliver through the small team that had been established, the officials said.

Now, an intensified process started to get more hostages out. When this happened, Burns began speaking regularly with Mossad director David Barnea.

Biden saw an opportunity to gain the release of a large number of hostages and that a deal for prisoners was the only realistic path to securing a pause in the fighting, the officials said.

On Oct. 24, with Israel poised to launch a ground offensive in Gaza, the U.S. side got word that Hamas had agreed to the parameters of a deal to release women and children, which would mean a pause and a delay in the ground invasion.

U.S. officials debated with the Israelis whether or not the ground offensive should be delayed.

The Israelis argued that terms were not firm enough to delay, since there was no proof of life for the hostages. Hamas claimed they could not determine who was being held until a pause in fighting began.

Americans and Israelis viewed the Hamas position as disingenuous. The official said Israel's invasion plan was adapted to support a pause if a deal came together.

Biden then engaged over the next three weeks in detailed talks as proposals about a potential hostage release were traded back and forth. Demands were made that Hamas produce the lists of hostages it was holding, their identifying information, and guarantees of release.

The process was long and cumbersome - communication was difficult and messages had to be passed from Doha or Cairo into Gaza and back, the officials said.

Biden held a previously undisclosed phone call with the Qatari prime minister when the phasing of releases began to take shape, the official said.

Under the agreement that was taking shape, women and children hostages would be freed in a first phase, together with a commensurate release of Palestinian prisoners from the Israelis.

The Israelis insisted Hamas ensure all women and children come out in this phase. The U.S. side agreed, and demanded through Qatar proof of life or identifying information for women and children held by Hamas.

Hamas said it could guarantee 50 in the first phase, but refused to produce a list of identifying criteria. On November 9, Burns met in Doha with the Qatari leader and the Mossad's Barnea to go through the texts of the emerging arrangement.

The key obstacle at that point was that Hamas had not clearly identified who it was holding.

Three days later, Biden called the emir of Qatar, Sheikh Tamim bin Hamad Al Thani, and demanded to know the names or clear identifying information for the 50 hostages including ages, gender and nationalities. Without the information, the official said, there was no basis to move forward.

Shortly after Biden's call, Hamas produced details for the 50 hostages it said would be released in the first phase of any deal.

Biden in a Nov. 14 call urged Netanyahu to take the deal - Netanyahu agreed.

McGurk saw Netanyahu that same day in Israel. Walking out of a meeting, Netanyahu grabbed McGurk’s arm and said “we need this deal” and urged Biden call the emir of Qatar on the final terms, one of the officials said.

Talks stalled as communications went dark in Gaza.

When they resumed, Biden was in San Francisco attending an Asia-Pacific summit. He called the emir of Qatar and told him this was the last chance, and the emir pledged to apply pressure to close the deal, the officials said.

"The president insisted the deal had to close, now. Time was up," one official said.

On Nov. 18, McGurk met in Doha with the Qatari prime minister. Burns was dialed in after he spoke with Mossad. The meeting identified the last remaining gaps toward a deal.

The agreement was now structured for women and children to be freed in the first phase, but with an expectation for future releases and the aim to bring all hostages home to their families.

In Cairo the next morning, McGurk met with Egypt intelligence chief Abbas Kamil. Word came from Hamas leaders in Gaza that they had accepted nearly all the agreements worked out the day before in Doha.

Only one issue remained, tied to the number of hostages to be released in the first phase and the ultimate structure of the deal to incentivize releases beyond the 50 known women and children, the officials said.

A flurry of additional contacts ensued, and the deal finally came together.