When President-elect Donald J. Trump’s Middle East envoy, Steve Witkoff, met with Israeli Prime Minister Benjamin Netanyahu on Saturday to press him for a ceasefire agreement in Gaza, there was someone on the speakerphone: Brett McGurk, Biden’s chief negotiator in Middle East for a long time.
It was a vivid example of cooperation between two men who are bitter political rivals, and whose relationship has been described as toxic. Rarely have teams of incumbent and incoming presidents from different parties worked together at such a high-stakes moment, when the fate of American lives and the future of a devastating war hung in the balance.
Both Mr. Trump and Mr. Biden have publicly claimed credit for the hack.
“This EPIC ceasefire agreement could only have happened as a result of our historic victory in November,” Mr. Trump wrote on his social media site even before the deal was officially announced in the Middle East.
At the White House, Biden told reporters that his administration had worked tirelessly for months to convince both sides to stop fighting. He called it “one of the most difficult negotiations I have ever witnessed” and praised “an exceptional team of American diplomats who worked nonstop for months to get this done.”
As he left the room, a reporter asked Mr. Biden: “Who gets the credit for this, Mr. President, you or Trump?” Mr. Biden stopped, turned and smiled.
“Is this a joke?” he asked.
But despite the tension between the incumbent and the incoming president, their representatives in the Middle East described a cooperative working relationship in the weeks after Election Day.
“Brett is at the forefront,” Mr. Witkoff said last week at Mar-a-Lago, Mr. Trump’s club in Florida, describing the working relationship. That description was accurate by all accounts, even if it did not match what Mr. Trump had said moments earlier in one of several statements in which he described his negotiators as critical players.
In fact, Mr. Trump’s threat that “all hell” will break loose if an agreement is not reached before his inauguration on Monday may have helped spur the Hamas leadership to make final decisions. But people familiar with the negotiations said Wednesday’s announcement of an agreement to temporarily end hostilities in Gaza was the result of months of work by Mr. McGurk in the Middle East, culminating in several weeks of carefully coordinated efforts by Mr. Witkoff.
Mr. Witkoff, 67, an outspoken real estate investor from the Bronx, settled in Qatar largely for negotiations, knowing that whatever Mr. McGurk negotiated, he would have to implement. In fact, the 33 hostages to be released under the ceasefire agreement may not gain freedom until Inauguration Day or after. The ceasefire is scheduled to end after six weeks, unless the second phase of the agreement is activated.
The aim behind this was to send a unified message that the fighting must end and that the hostages held by Hamas must be released. One person familiar with the negotiations, who like others spoke on the condition of anonymity to describe the discussions, said Mr. McGurk was more involved in crafting the details of the agreement, while Mr. Witkoff’s role was to make clear that Mr. Trump wanted a deal by the time it opened.
The president-elect has also set some early standards in his dealings with Mr. Netanyahu — who, for all his support for Mr. Trump in the election, was seen by the Trump camp as stalling on a deal. Mr. Witkopf flew to Israel from Doha on Saturday — despite it being Saturday — to underscore the message that Mr. Netanyahu should get on the plane.
Mr. Witkopf’s work, including meeting with Mr. Netanyahu, helped Mr. McGurk and the Biden administration put pressure on both sides during the negotiations, according to the person familiar with the talks.
It was not at all clear whether such an arrangement would work in the days immediately after Trump won a second term.
He and Mr. Biden have barely spoken in recent weeks, their already strained relationship affected by the Trump team’s determination to get rid of White House staff and the Biden team’s issuance of last-minute orders to corral the new administration.
In his remarks Wednesday, Biden acknowledged a certain level of cooperation and respect among their aides.
“This deal was developed and negotiated under my administration, but its terms will be implemented mostly by the next administration,” Biden told reporters. “For the past few days, we’ve been talking as a team.”
But he did not give Mr. Trump more credit for aiding the effort. For his part, the president-elect said that he was “pleased” with the release of the American hostages, but he did not mention Mr. Biden or the work of the current administration.
“We have accomplished so much even without being in the White House,” Mr. Trump wrote. “Just imagine all the wonderful things that will happen when I return to the White House, and my administration is fully confirmed, so they can secure more victories for the United States!”
Both leaders left it up to staff to describe how they worked together in the Gaza negotiations.
A person familiar with the effort said the close partnership between Mr. McGurk and Mr. Witkoff was part of an “incredibly efficient” process through which the Biden administration finalized a deal that the Trump administration would have to oversee.
This cooperation began shortly after Mr. Trump won the election and appointed Mr. Witkoff to be his envoy to the region. Biden administration officials said they believed the momentum for an agreement began before that, when Biden helped broker a separate agreement to end the fighting between Israel and Hezbollah in Lebanon. This isolated Hamas and helped convince the group that a ceasefire was in its interest, according to Biden officials.