(CNN) President Donald Trump surprised the leaders of his own party in Congress on Wednesday when he backed a deal pushed by Democrats to attach hurricane relief money to a shorter-term bump in the debt ceiling as well as keeping the government open, cutting off his own Treasury secretary to strike a deal.
The decision was one of the most fascinating and mysterious moves he's made with Congress during eight months in office.
The remarkable turn of events left Republican congressional leaders, in control of both chambers of the legislative branch, "shell-shocked" and "visibly annoyed," and showcased how a President who also authored "The Art of the Deal" actually cuts one.
Trump's stunning agreement to endorse a plan proposed by Senate Minority Leader Chuck Schumer and House Minority Leader Nancy Pelosi came during a Wednesday morning meeting with leaders from both parties in the Oval Office, the first such meeting of Trump's presidency.
Several Republicans briefed on the meeting said that Trump, who has been absent a major legislative achievement for his first seven months in office, was hungry for a deal. It also came after he was warned of a packed legislative calendar that could have pushed off tax reform past this fall.
"The President was in deal-cutting mode," a Republican familiar with the meeting told CNN. "He was sick of this fight."
In Wednesday's session, Republican leaders -- including House Speaker Paul Ryan and Senate Majority Leader Mitch McConnell -- first pushed lifting the debt ceiling for 18 months. With no agreement at hand, they decreased the timeframe to a year, before finally proposing a six-month extension.
Democratic leaders dismissed all of their proposals, standing firm by their three-month extension plan, which they had publicly endorsed in a joint statement before the meeting.
A source briefed on the meeting said the top Hill Republicans -- McConnell and House Majority Leader Kevin McCarthy -- and Trump's own Treasury secretary, Steven Mnuchin, echoed Ryan's concerns about such a debt limit and warned against problems caused by a shorter-term solution.
According to one source familiar with the events, Mnuchin was in the middle of arguing for a longer-term deal in the meeting when the President abruptly cut him off and sided with the Democrats.
A senior Republican source described Trump as being in "Apprentice" mode, a reference to the reality show that made the President a TV star. Trump just decided to listen and then make a decision on the spot, the source told CNN.
McConnell and Ryan were "blindsided by this," a Republican official told CNN. In fact, hours before Trump agreed to Democrats' proposal, Ryan had publicly called such a plan "ridiculous" during a news conference. The GOP leaders had no heads up or warning that Trump's decision would happen, Republican officials told CNN. Another senior GOP source described the two leaders as "shell-shocked."
A source familiar with the meeting said McConnell decided to throw in a continuing resolution to keep the federal government funded through December 15, so that the deal could all happen at once.
At some point toward the end of the meeting, the President's oldest daughter and senior adviser, Ivanka Trump, stopped by the meeting to specifically sell the child tax credit, according to a senior GOP source. According to one congressional source briefed on the meeting, some Republican leaders were "visibly annoyed" during Ivanka Trump's appearance at the meeting, a description Ryan's spokeswoman AshLee Strong said was untrue.
White House legislative director Marc Short told CNN, "We asked Ivanka to briefly join the meeting for an update on the child care tax credit and how we are working to make tax reform a bi-partisan issue. It was a quick and productive conversation."
The meeting came a day after Trump met separately with Republican congressional leaders and listened as they sought to deliver a reality check on tax reform.
Tax reform was unlikely to glide through Congress and hit the President's desk before Thanksgiving, as Trump has hoped would be the case, the GOP leaders told him Tuesday. Leadership needed time to build consensus among Republicans and, most importantly, the legislative calendar in September was packed with a need for action that superseded tax reform, according to two sources familiar with Tuesday's meeting.
White House officials had warned the congressional leaders that Trump might be upset by the lengthier timeline. Instead -- to their surprise -- Trump was "understanding" and "pragmatic," two sources briefed on the meeting said.
Less than 24 hours later, Trump agreed to the Democrats' deal -- clearing the September calendar Trump had been warned about.
It wasn't clear if Republican leaders' warnings unwittingly encouraged the President to cut a deal with Democrats, but a senior White House official said Trump went into Wednesday's meeting eager to cut a deal that would clear the way for tax reform.
Following the meeting, Trump and his team left for his speech in North Dakota on tax reform, now an issue that at least one aide said was made more difficult by Trump's move.
"Now nothing will get done between now and Dec. 15," one Republican aide told CNN in an email. "You think people will vote for a budget now?"
Other congressional Republican sources argued this wasn't just the President undermining GOP leaders politically, but ultimately on policy. In mid-December, with winter holidays around the corner, Democrats will have another chance to use must-pass legislation as leverage for other priorities. A senior Democratic source conceded to CNN that Republicans are right, which is why Democratic leaders united before the White House meeting on demanding only a three-month extension for the debt ceiling along with hurricane funding.
Sen. Ben Sasse, a Nebraska Republican and consistent Trump critic, issued a one line statement: "The Pelosi-Schumer-Trump deal is bad."
McConnell said later that he will support the deal agreed to by Trump, but he made very clear following the Republican policy lunch that this was an agreement between Trump and Democratic leaders. He wouldn't say if he was surprised by the deal, but said Trump's "rationale" was the "feeling that we need to come together."
On board Air Force One, Trump sounded optimistic and chummy with Democratic leaders Schumer and Pelosi, both of whom he's repeatedly lambasted on the campaign trail and since taking office.
"We discussed that also today, and Chuck and Nancy would like to see something happen, and so do I," Trump told reporters. "And I said if we can get something to happen, we're going to sign it and we're going to make a lot of happy people."
Schumer has openly talked about driving a wedge between the President and the GOP. The New York Democrat told CNN in January that "the only way we're going to work with him is if he moves completely in our direction and abandons his Republican colleagues."
Short said Wednesday that Trump agreed to the funding and debt ceiling deal with Democrats in order to make way "clear the deck" for his primary legislative priority: tax reform.
"We believe that it's something to clear the deck," Short said, adding it would allow Congress to "focus on tax reform for the American people."
A senior White House official said tax reform was indeed the driving force -- he went into the meeting aiming to "clear the decks" so that Congress could move forward on his legislative priority.
That plan was no one else's but the President's, a GOP leadership aide said.
"It wasn't a good strategy. And it wasn't his administration's strategy," the aide said. "It was his."
This story has been updated.