Get breaking news alerts and special reports. The news and stories that matter, delivered weekday mornings.

WASHINGTON — President Donald Trump campaigned against Republicans and Democrats alike in 2016, selling himself as the ultimate dealmaker who could cut through the dysfunctional partisan swamp to get things done. But until recently, there weren’t any deals to speak of.

That may be changing — but will the core, energized base of either party allow their leaders to make a bargain that could be seen as selling out their principles?

On the surface, the moment seems ripe for horse trading.

Trump’s relationship with the GOP is on rocks and he has no qualms about venting his frustration with the party's congressional leaders, to whom he has largely outsourced his policy agenda with little to show for it in return.

That’s opened the tantalizing possibility of a new alliance with a Democrat who can “speak New York to the President,” as House Democratic Leader Nancy Pelosi said of Chuck Schumer, her Senate counterpart from Trump's home state.

It took just two days for Pelosi and Schumer to deliver the votes they promised on a short-term deal to raise the debt ceiling and fund the government, leaving Trump basking in a taste of the positive media coverage that often accompanies bills with a bipartisan sheen.

Now there’s an apparent agreement to legalize so-called Dreamers, the children of undocumented immigrants who had been protected by the federal DACA program until Trump ordered it to be ended in six months.

Will an infrastructure package be next? Or even more?

The details of an agreement on the DACA program are still murky and there are ample opportunities for the notoriously mercurial Trump to reverse himself yet again.

But the possibility of a political realignment will test how how much pain leaders in each party are willing to endure from their own supporters who view compromise, especially on key issues like immigration, as tantamount to surrender.

“I hope and pray that Pelosi and Schumer are more sophisticated and smarter than everyone else that's been duped by Donald Trump,” said liberal firebrand Rep. Luis Gutierrez, D-Ill.

Related: Trump Talking DACA With Democrats Has Republicans on Edge, Again

On the right, some of Trump’s allies exploded over the news of Trump’s handshake deal with the Democrats to provide protections for Dreamers in exchange for more border protections, but apparently excluding a wall.

Let our news meet your inbox. The news and stories that matters, delivered weekday mornings. This site is protected by recaptcha

Breitbart News, once again home to Trump’s former chief strategist Steve Bannon, dubbed him “Amnesty Don” on the website's front page. Ann Coulter, author of “In Trump We Trust,” brought up impeachment. And Rep. Steve King, R-Iowa, the most prominent immigration hardliner in Washington, tweeted that the “Trump base is blown up, destroyed, irreparable, and disillusioned beyond repair.”

U.S. Senate Minority Leader Chuck Schumer (D-NY) makes a point to President Donald Trump in the Oval Office prior to his departure from the White House Sept. 6, 2017 in Washington. Alex Wong / Getty Images

But it’s not clear how much support the hardliners actually command within the party.

The main reason Republicans failed to pass immigration reform in recent years, despite strong interest from party leaders, was a pervasive fear among the rank-and-file that they would be attacked by the loud, aggressive voices on the right.

The loudest of those voices had been their own party’s president, but he's now pushing them from the left and giving them political cover.

Rep. Chris Collins, R-N.Y., an early Trump supporter, said the president’s voters understand that there is a difference between Dreamers and the broader undocumented population, and that it is “pretty universally accepted” they should be allowed to stay in the country. “We’re a compassionate country,” he said.

Conservative lawmakers are already rushing to blame their own leaders rather than Trump for his shift towards Democrats, reflecting the power imbalance between the two sides.

“I think it’s pretty clear that it’s a warning to Republicans,” said Congressman Lou Barletta, R-Penn., a longtime immigration hawk who is running for Senate in 2018. “If we can’t get things done then we’re giving him no choice but to work with Democrats.”

Rep. David Brat, R-Va., who unseated former Majority Leader Eric Cantor while running to his right on immigration, said Trump’s word carried “huge, huge, huge” weight with his constituents on the issue. He said it was too early to evaluate a potential deal, however.

Related: How to Make Sense of Trump's Deals With the Democrats

The best evidence that Trump might survive a deal unscathed is how his supporters behaved during the campaign itself. This week was far from the first time Trump waffled on immigration. Before he became the candidate of deportation, he attacked Mitt Romney for being too hard on undocumented immigrants. Even late in the 2016 campaign, he publicly debated whether to allow some undocumented immigrants to remain in the country before dropping the idea.

But the story might different on the other side of the bargaining table, where liberal Democrats have a visceral aversion to doing anything to bolster this president, setting an especially high bar for any compromise.

“The base simply does not trust Schumer,” said Murshed Zaheed, the political director of the liberal activist group CREDO.

In the halls of Congress, progressive lawmakers are more pragmatic, but still skeptical of working with someone they don’t trust.

"I don't think the president actually understands what he's saying half the time, so I'm afraid that if you strike a deal with him that he'll go back on his word at any point,” said Rep. Ruben Gallego, D-Ariz., a co-chairman of the Congressional Hispanic Caucus.

Even some of the party’s liberal stalwarts have caught an earful from the anti-Trump “resistance” movement, which has threatened to mount primary challenges to Democrats that step out of line.

In the days after Trump’s election, Sens. Bernie Sanders, I-Vt., and Elizabeth Warren, D-Mass., quickly backed off initially optimistic talk about working with Trump on an infrastructure package and other issues after progressive activists privately warned them they were misreading their base, according to several activists.

At the same time, moderates facing daunting 2018 reelection bids are open to working with Trump on tax reform.

“I'm looking for a balanced approach to fixing things. And I'm open minded,” Sen. Joe Manchin, D-W.V., one of 10 Senate Democrats up for reelection next year in a state that Trump won, told MSNBC after a bipartisan dinner this week at the White House to discuss tax reform and infrastructure.

President-elect Donald Trump greets House Minority Leader Nancy Pelosi, D-Calif., and other Congressional leaders as he arrives for his inauguration ceremony at the Capitol in Washington on Jan. 20, 2017. J. Scott Applewhite / Getty Images file

Trump also met with House Democrats and Republicans who are pushing a compromise health care bill to shore up Obamacare rather than sabotage it. If he signed on, it would be a major departure from his threats to let the program “implode” in order to tag Democrats with the blame.

And ultimately, say Democrats of all stripes, what matters most is outcomes.

“I’m sure there’ll be some angst if Democrats work with a president who’s very unpopular in our base. But that’s the position we’re in,” Sen. Chris Murphy, D-Conn. “He’s the president of United States.”

Rep. Beto O’Rourke, D-Texas, who is running for the Senate against Ted Cruz, went up to Pelosi on the House floor Thursday and told her, “Great work, keep going to the White House — it's working."

He said he wasn't worried about giving Trump a win. “Politics be damned, let's do the right thing for the country," O’Rourke said. "Work with anyone, anytime, anywhere, and that includes the president."