WASHINGTON ― Democratic leaders found themselves in the unusual position of being on the same side as President Donald Trump on Wednesday, reaching agreement on a plan to keep the government funded and raise the debt ceiling.

Trump met with Senate Minority Leader Chuck Schumer (D-N.Y.) and House Minority Leader Nancy Pelosi (D-Calif.), as well as Senate Majority Leader Mitch McConnell (R-Ky.), House Majority Leader Kevin McCarthy (R-Calif.) and House Speaker Paul Ryan (R-Wis.), at the White House on Wednesday.

“In the meeting, the President and Congressional leadership agreed to pass aid for Harvey, an extension of the debt limit, and a continuing resolution both to December 15, all together. Both sides have every intention of avoiding default in December and look forward to working together on the many issues before us,” Schumer and Pelosi said in a joint statement after the meeting.

Democrats had gone into the meeting hoping to get exactly this outcome. A congressional aide briefed on the meeting said Republican leaders wanted an 18-month debt ceiling hike, and then suggested six months instead. Pelosi and Schumer dismissed a six-month hike, and Trump eventually agreed to the Democrats’ three-month proposal.

Alex Wong via Getty Images Senate Minority Leader Chuck Schumer (D-N.Y.) makes a point to President Donald Trump in the Oval Office on Wednesday.

Another source briefed on the meeting said Treasury Secretary Steve Mnuchin sided with the Republican leaders in the room in wanting a longer debt limit extension. When it was clear the congressional leaders were going to agree to disagree, Trump unexpectedly agreed to the three-month extension.

Republicans often need Democratic votes to raise the debt ceiling, because many conservatives oppose increasing the government’s borrowing limit without spending cuts to decrease the deficit. With a shorter-term debt ceiling hike coming up in December at the same time as a government funding fight, Democrats will have more leverage in the budget battle.

But by siding with Democrats, Trump rejected the wishes of his own party ― a move that reportedly left Republicans furious ― and it’s not clear how many GOP lawmakers will go along with this deal.

McConnell said he would add the three-month funding and debt ceiling extension to legislation providing $7.85 billion in aid for Hurricane Harvey.

“The president can speak for himself, but his feeling was that we needed to come together to not create a picture of divisiveness at a time of genuine national crisis. And that was the rationale,” McConnell told reporters, distancing himself from the deal.

Alex Wong/Pool via Bloomberg via Getty Images Congressional leaders met with the president and vice president at the White House Wednesday.

Earlier Wednesday, Ryan derided Democrats’ proposal to raise the debt ceiling for three months, calling the idea “ridiculous” and “disgraceful.”

“We’ve got all this devastation in Texas. We’ve got another unprecedented hurricane about to hit Florida. And they want to play politics with the debt ceiling?” Ryan told reporters. “That will strand the aid that we need to bring to the victims of these storms that have occurred or are about to occur.”

Mnuchin has said that he and the president wanted the debt ceiling hike to be tied to aid for Hurricane Harvey ― a proposal opposed by many conservatives.

Congress has until Sept. 30 to reach a funding deal to avoid a government shutdown. Mnuchin said Congress needs to raise the debt ceiling by Sept. 29, or else the United States risks default and throwing the economy into a tailspin.

Sen. Thom Tillis (R-N.C.) admitted that Democrats walked away with a pretty good deal.

“For people who want to keep score, maybe that’s true,” he said when asked if Democrats received everything they wanted from Trump.

Sen. Susan Collins (R-Maine) also said she was “very surprised” by the three-month debt limit deal.

The Pelosi-Schumer-Trump deal is bad. — Senator Ben Sasse (@SenSasse) September 6, 2017

Marc Short, the White House director of legislative affairs, said Trump agreed to this deal with Democrats because to “clear the decks” for tax reform.

Schumer and Pelosi said they also discussed the fate of undocumented immigrants who came to the United States as children and now risk deportation, thanks to an order by Trump.

“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,” they said.

Democrats say that this new deal with Trump strengthens their hand in passing the DREAM Act, which would provide a path to citizenship for these undocumented immigrants. They’ll be able to use the leverage they have on the debt ceiling to press for what they want legislatively, with the DREAM Act being high on the list.

The congressional aide briefed on the meeting also said Ivanka Trump, the president’s daughter, came into the Oval Office toward the end to “say hello,” at which point the meeting went off topic. The GOP leaders were reportedly visibly annoyed by her presence there.

Speaking with reporters aboard Air Force One on Wednesday, Trump said he had a “very good meeting” with Pelosi and Schumer. He did not mention any of the GOP leaders.

Igor Bobic contributed reporting.

Want more updates from Amanda Terkel? Sign up for her newsletter, Piping Hot Truth, here.