Donald Trump let the news cameras stay in the room on Tuesday, when he convened Democrats and Republicans at the White House to discuss immigration. “I’ll sign whatever bill they send me,” he said, referring to the lawmakers there who had spent the past four months in negotiations over how to protect seven hundred thousand undocumented immigrants, known as Dreamers, who came to the U.S. as children. In September, the President cancelled Deferred Action for Childhood Arrivals (DACA)—an Obama-era policy that had granted Dreamers work permits and shielded them from deportation—while simultaneously calling on Congress to come up with a legislative solution. On Thursday afternoon, two days after Trump promised to back any deal sent to him, a bipartisan group of senators—three Republicans and three Democrats—announced a preliminary agreement designed both to protect Dreamers and to attract enough conservative support to get a bill through Congress: DACA recipients would receive a path to citizenship in exchange for an increase in funding for border security and certain changes to the legal-immigration system. “President Trump called on Congress to solve the DACA challenge,” the six senators said in a statement. “We have . . . reached an agreement in principle. . . . We are now working to build support for that deal.”

After issuing the statement, Lindsey Graham and Dick Durbin, the Republican and Democrat leading the Senate negotiations, travelled to the White House, where they were expecting to meet privately with Trump in the Oval Office. When they got there, he wasn’t alone: Representative Bob Goodlatte and Senator Tom Cotton, two of the most stridently anti-immigrant members of the Republican caucus, were already with him. So was Stephen Miller, the President’s senior policy adviser, who has tried, repeatedly, to scuttle the DACA negotiations. Trump bristled when Durbin and Graham began briefing him on the details. “Why are we having all these people from shithole countries come here?” Trump said, as first reported by the Washington Post. Then he explained that he’d rather have more immigrants from countries like Norway.

As news of Trump’s comments spread, even jaded congressional insiders expressed shock. According to one Democratic aide, the White House “had been getting briefed on the details” of the plan since Wednesday. But Trump reacted negatively on Thursday only after the senators had announced the deal publicly.

On Thursday night, White House staffers defended their boss’s outburst, claiming that he was sending a message of toughness and inflexibility to his political base. Yet the contrast with Trump’s posture earlier this week—when he played up his image as a conciliator who could “take the heat” from the far right—was impossible to explain away. On Tuesday, Graham had told Trump that he, as President, was in a position to accomplish what none of his predecessors could. “You have created an opportunity here, Mr. President, and you need to close the deal,” he said. Before Trump’s “shithole” comment became public, one immigration advocate close to the negotiations told me that the President seemed to have taken Graham’s arguments seriously. “He wants to be able to say he’s the one who came up with a solution,” the advocate told me. “That’s all he cares about. And Graham seems to have sold him on that.”

Now Trump’s outburst has threatened to undercut a deal that he may have helped facilitate. The lawmakers whom Trump hosted at the White House on Tuesday hadn’t been forewarned that they would be speaking in front of cameras, and that appears to have created the conditions for some genuine candor in the negotiations. “If they’d come in with talking points for the cameras, they would have been more polished,” a former Republican aide, with years of experience on immigration issues, told me. “These were the principals talking, without their aides.” The fact that Trump was attempting to take such an active role in the exchange may also have left Republicans feeling like they had some cover to support a DACA deal without fear of getting lambasted by the President. “Trump set himself up in the room to be the center of that negotiation,” the former aide said. “It’s going to be hard for him not to be invested in what the product is now.” The immigration advocate conceded, “That crazy meeting really shook things up.”

The preliminary deal announced on Thursday went further in protecting Dreamers than some expected: it offered a path to citizenship not only for current DACA recipients but also for those eligible Dreamers who hadn’t yet signed up before the program was cancelled. The deal also allocated roughly three billion dollars for border-security measures; revised the so-called visa-lottery system, which grants green cards to people from countries with low rates of immigration to the U.S.; and offered temporary protected status to the parents of DACA recipients. The border-security money and lottery-system changes are priorities for conservatives. But creating protections for the parents of Dreamers was a significant concession to Democrats, who are facing pressure from the left to fight harder for Dreamers. “There’s no way this could move in the House,” the former Republican aide told me. “You’re going to have one hundred and fifty Republicans revolt against that. The whole point with the Dreamers is that they’re here through no fault of their own. So the idea of rewarding people who are responsible, what’s that going to get you?” The former aide wasn’t surprised that the White House refused to embrace the proposal, and even some immigration advocates told me that they’d expected some of the terms of the deal to eventually change.

As of Friday morning, the proposal was still under discussion, according to two other aides close the negotiations. When Cotton blasted the deal on Thursday—he called it “a joke”—Graham and his Republican partners, Jeff Flake and Cory Gardner, held their ground. “We are at a deal,” Flake said. “It’s the only game in town. There is no other bill.” Next week, Congress will have to vote to continue funding the government and, shortly after that, to approve a budget for the upcoming year. Republicans need Democratic votes in the Senate for both maneuvers, but it seems unlikely that the Democratic leadership will hold these measures up over the DACA dispute.

The senators who reached the deal are now honing the specific details, and beginning to sell the plan to their colleagues in both parties. “There’s no deal yet,” someone close to the negotiations told me. “But that doesn’t mean the deal’s been rejected.” That may be a hard argument to sustain if the President continues fulminating against the terms. On Friday morning, Trump tweeted, “The language used by me at the DACA meeting was tough, but this was not the language used. What was really tough was the outlandish proposal made—a big setback for DACA!”