President Donald Trump just shivved his own party’s congressional leadership heading into the biggest month of legislative business this year.

Trump baffled congressional Republicans, and even some in his own administration, by quickly siding with Democratic leaders on a deal to fund the government and raise the federal debt ceiling for the next three months. It was a deal that his own party, led by Speaker Paul Ryan (R-WI), opposed, including in a public statement just hours before a closed-door White House meeting between the president, fellow congressional leaders, and Treasury Secretary Steve Mnuchin.

For all his famed negotiating skills, Trump emerged from the meeting having handed Democrats a legislative triumph. But according to sources close to Trump, the president was more than willing to cut the deal because he has grown tired, if not resentful, of Republican leaders on Capitol Hill.

Multiple West Wing sources told The Daily Beast how the president was looking to strike a quick and easy deal—and that his speed reaching this specific arrangement was in part ensured by his resentment towards Republican leaders, who Trump views as hostile, insufficiently loyal, and impotent. It was well-known within the White House that President Trump, going into the meeting, was “not looking to do [Ryan and McConnell] any favors,” as one White House official put it.

Simply put, the president made a “deliberate decision not to care about Ryan’s feelings” and did what he wanted, another White House adviser said.

“I think it was calculated, in his unique way. Republicans can’t get anything done, so maybe the other side will,” a senior Trump administration official said of the deal, which will forestall a government shutdown until mid-December and allow the government to continue borrowing money until around the same time. “At the very least,” the administration official added, “it says, ‘don’t take me for granted.’”

The White House did not respond to a request for comment on this story. While officials spoke on the condition of anonymity because they were not cleared to discuss intraparty tensions.

But the general gist of Trump’s willingness to turn on his own party leadership was confirmed by a Hill aide briefed on the meeting who said the president quickly dispensed with Ryan and Senate Majority Leader Mitch McConnell’s pitch for an 18-month debt limit hike; following by their request for a six-month debt limit hike; before settling on Senate Minority Leader Chuck Schumer and House Minority Leader Nancy Pelosi’s opening offer of a three-month hike.

Addressing reporters shortly after the deal was finalized, Trump completely neglected to mention congressional leaders of his own party, emphasizing instead that “we had a very good meeting with Nancy Pelosi and Chuck Schumer.” Asked a followup about potential legislation to give legal protections to young undocumented immigrants, Trump was even more colloquial.

“Chuck and Nancy would like to see something happen, and so do I,” the president said.

That final debt and budget deal comes after months of deteriorating relationships between Trump and his party’s congressional leadership, spurred in large measure by the inability to advance legislation to repeal and replace the Affordable Care Act. Last month, the president reportedly berated the McConnell during a phone call for refusing to “protect” Trump from federal and congressional investigations into alleged Russian meddling in the 2016 election. According to The New York Times, the call “quickly devolved into a profane shouting match.”

But Trump didn’t just undercut Ryan and McConnell. He also contradicted his own Treasury secretary, who debated Schumer on the merits of the deal during Wednesday’s meeting. Officials at the Treasury were caught off-guard by the president’s decision, according to a source familiar with the situation, ultimately hearing about it through news reports. A Treasury spokesperson did not respond to a request for comment on the deal.

At 2 p.m. ET, about an hour after the deal was announced, counselor to the president Kellyanne Conway held a conference call with congressional Republican aides. According to a source on the call, Conway spent the first 15 minutes simply rattling off talking points about the importance of tax reform as baffled staffers awaited an explanation for the deal Trump had cut with leading Democrats.

Republican lawmakers were left to vent, some privately but others publicly. Sen. Ben Sasse (R-NE) issued a one-sentence statement: “The Pelosi-Schumer-Trump deal is bad.”

But others in the party came to Trump’s defense. Newt Gingrich, the former speaker of the House who has acted as a top informal adviser to the president, argued on Wednesday afternoon that Trump did “exactly the right thing.”

“On this particular topic... I would be inclined to take the deal and get to the next problem,” Gingrich told The Daily Beast. “Tactically, I was surprised they did it this fast. But they have to get the money out there.”

Shortly after the Wednesday meeting with congressional leaders, the White House began echoing those points. Marc Short, the White House’s director of legislative strategy, said the president was attempting to “clear the deck” for tax reform by getting tough budgetary issues out of the way.

Whether that push for tax reform was made easier or harder by Wednesday’s deal is unclear. A massive deadline could now await lawmakers in mid-December. And an already fraught relationship between Trump and GOP leaders became further defined by mutual distrust.

“I would like to think that Trump siding with Dems is some strategic move to put the Republican members on notice to play ball on the big items we said we’d do,” one Republican leadership aide told The Daily Beast. “But that’s giving a lot of credit, and part of me thinks Schumer talked first, and it was like, ‘OK, that sounds good.’”

—with additional reporting by Sam Stein