Paul and Mitch, take a seat: President Trump’s new best friends in Congress are Nancy and Chuck.

In a surprising blow to his own party’s congressional leadership, the president on Wednesday struck a deal with Democrats to package nearly $8 billion in Hurricane Harvey relief with a three-month extension of government funding and increase in the debt ceiling. Trump agreed to the request by House Minority Leader Nancy Pelosi and Senate Minority Leader Charles Schumer over the objections of Speaker Paul Ryan and Senate Majority Leader Mitch McConnell, who had wanted a longer increase in the debt ceiling to prevent Republicans from having to take multiple, politically painful votes to raise it in the coming months.

“We essentially came to a deal, and I think the deal will be very good,” Trump told reporters on Air Force One after meeting with the top four congressional leaders at the White House. In a sign of how the meeting went, he praised the two Democrats he had until recently called “obstructionists,” and he neglected to mention Ryan and McConnell at all.

Trump even held out the possibility of giving Democrats a much bigger prize in future negotiations: a permanent legislative fix for undocumented immigrants brought to the U.S. illegally as children who were protected from deportation under the Deferred Action for Childhood Arrivals program, which he announced would be winding down. “Chuck and Nancy would like to see something happen, and so do I,” the president said.

With Trump’s acquiescence to the Democrats’ fiscal demands, their chances of winning a DACA fix have also improved. Schumer and Pelosi specifically wanted only a short-term increase in the debt ceiling because it gives Democrats additional leverage to demand concessions during the next round of spending fights in December, when Congress will be under pressure to make a big year-end agreement before lawmakers go home for the holidays. Republicans know they can’t pass an increase in the debt ceiling without Democratic votes, and the more frequently they have to do it, the more bargaining power Pelosi and Schumer have.

“Both sides have every intention of avoiding default in December and look forward to working together on the many issues before us,” the two Democrats said in a joint statement after the White House meeting. Then they hinted that a DACA fix was next on their list of priorities: “As Democratic leaders, we also made it clear that we strongly believe the DREAM Act must come to the floor and pass as soon as possible and we will not rest until we get this done.”

Trump’s deal with Democrats was a particular humiliation for Ryan, who just hours earlier—and perhaps unbeknownst to the president—had denounced as “ridiculous” and “disgraceful” the exact terms that comprised the agreement. “I think that’s a ridiculous idea. I hope they don’t mean that,” the speaker told reporters when he was asked about the proposal from Pelosi and Schumer to tie a short-term debt-limit increase to the Harvey relief money. “I think it’s ridiculous and disgraceful that they want to play politics with the debt ceiling at this moment when we have fellow citizens in need.”

In the White House meeting, every Republican in the room but Trump—Ryan, McConnell, House Majority Leader Kevin McCarthy, and Treasury Secretary Steven Mnuchin—opposed the Democratic plan, according to multiple people briefed on the discussion. The Republicans first proposed an 18-month extension of the debt limit, which would mean Congress wouldn’t have to vote again on the issue until after the 2018 midterm elections. Then they floated a six-month extension. But when the negotiation came to a standstill and it became clear neither side would budge, Trump sided with Democrats and backed a three-month extension both of federal spending and the debt ceiling.

Another aide briefed on the meeting said that toward its conclusion, Ivanka Trump entered the room to say hello to the leaders and the discussion veered off-track. “Republican leaders were visibly annoyed by Ivanka’s presence,” the aide said. (A Ryan spokeswoman replied: “That’s not true.”)

The agreement must still pass the House and Senate, and although most Democrats will likely vote for it, Republican support could be tough to come by, and blowback from conservatives could be intense. “The Pelosi-Schumer-Trump deal is bad,” Senator Ben Sasse of Nebraska tweeted in one early review.

The House on Wednesday passed legislation to provide $7.85 billion in federal assistance to Texas and Louisiana. McConnell acknowledged that the president had sided with Democrats, and he said that in deference to Trump’s wishes, he would amend the bill this week to add the three-month continuing resolution and debt-ceiling provisions. And, in a signal to fellow Republicans, the majority leader said he would vote for it. Trump’s feeling, McConnell said, “was we needed to come together to not present a picture of divisiveness.” He made no mention of his own recent public spat with the president, nor did he opine on Trump’s strategic break with GOP leaders.

In true Beltway fashion, Democrats crowed over an agreement that will bring only a few months of fiscal peace. “This was a really positive step forward,” Schumer said, hailing it as a victory for the nation. But its significance was more in its precedent than the substance: A frustrated president, bereft of legislative wins and desperate to make a deal, turned away from his party and into the unlikely arms of the opposition.