The prime minister of Qatar believed he had struck a deal Wednesday evening in his office complex by the water in Doha. After 466 days of fighting, Hamas negotiators, led by a stout former legislator, had departed the prime minister’s office after abandoning an eleventh-hour demand that was the final significant barrier to a cease-fire in Gaza.

Downstairs, reporters had started to gather in an auditorium, anticipating the prime minister, Sheikh Mohammed bin Abdulrahman Al Thani, to declare that he and other mediators had finally reached an agreement. Sheikh Mohammed crafted his statement with the assistance of two U.S. envoys.

According to two persons with knowledge of the discussions, there was an unexpected new issue.

The leaders of Israel’s two primary intelligence services, who were part of the Israeli delegation, had their own last-minute request in a different room on the sixth floor. Benjamin Netanyahu, the prime minister, intended to make clear the identities of a few Palestinian inmates who Israel will free as part of the agreement.

Sheikh Mohammed sat in his office with President Biden’s chief negotiator Brett McGurk and President-elect Donald J. Trump’s assistant Steve Witkoff, hopeful that their efforts had not been in vain as they attempted to iron out the last snag.

Conversations with nine individuals who were either involved in or informed on the negotiations—some of whom talked on condition of anonymity to discuss delicate diplomacy—form the basis of this account of the last days of negotiations.

Hours after Israel made its latest demand, the truce that was finally declared at the tardy news briefing was largely identical to versions that had been pushed for the majority of the previous year by mediators from Egypt, Qatar, and the Biden administration, whose delegates regularly met with the warring parties in Cairo, Doha, and other European capitals throughout 2024.

The unexpected collaboration of the envoys of the present and future presidents of the United States, who collaborated with the prime minister of Qatar in lengthy late-night sessions, was what ultimately made the deal last week. Although Mr. Biden and Mr. Trump have vied for attention, the truth is that each of their aides played a pivotal role in the last push, employing distinct strategies to persuade the Israeli leadership to reach an agreement while Sheikh Mohammed concentrated on Hamas.

The two Americans and the Israeli and Palestinian delegations began spending long days at the prime minister’s compound near the ancient market in downtown Doha last Sunday. The delegations including Egyptian and Qatari officials do not communicate directly with one another.

Former U.S. ambassador to Israel Thomas R. Nides stated, “These three people and the three worlds they represent are not natural partners, but their combination was the only thing that was going to get this done.” “You required pressure from all sources, including the Arab world, Biden, and Trump.”

Negotiations had been pushed on for over a year by a variety of authorities and interlocutors; on the American side, Mr. McGurk had assisted in supervising U.S. mediation efforts since the first weeks of the war, along with other important figures, such as William J. Burns, the head of the C.I.A.

However, the triumvirate was the decisive factor in the latter days. Nearly a year ago, Mr. McGurk, a seasoned diplomat with a lengthy history of working in the Middle East, assisted in creating the intricate terms of the agreement. Israel ultimately agreed to the terms of the sale thanks in large part to Mr. Witkoff, a real estate mogul who plays golf with Mr. Trump. Sheikh Mohammed was the one who convinced Hamas to make important concessions and gave both parties a workspace to work out the last issues.

Hamas has agreed to progressively free 33 hostages taken during the group’s October 7, 2023, attack on Israel, which marked the beginning of the conflict. The agreement they signed calls for a halt in hostilities for at least six weeks. Israel has agreed to let hundreds of thousands of displaced Gazans to return to their homes in exchange for the gradual release of some 1,000 Palestinian inmates, some of whom are serving life terms for murder.

reporting.