Political tremors seized both major parties on Thursday in the wake of President Trump’s sudden alignment with congressional Democrats, leaving Republicans alarmed about the unraveling of their relationship with the White House and uncertain about the prospects for their policy ambitions this fall.

In the span of 48 hours, Trump cut a deal with Democrats to keep the government funded and raise the nation’s borrowing authority, advanced talks with the senior Senate Democrat on a permanent debt ceiling solution and followed the advice of the top House Democrat, who urged him to use Twitter to ease the fears of young undocumented immigrants.

The developments confounded congressional Republicans and Democrats at the Capitol, where some long-standing political norms seemed to many to be shattered. The upheaval also raised new questions about how Trump plans to approach the looming debates over tax reform, immigration, government funding and the nation’s debt — and where congressional Republicans fit in.

“Haven’t seen anything like it before,” said Sen. John McCain (R-Ariz.), who has served in the Senate for three decades. Of Trump, McCain said: “I have no way of divining his motives. I’m a pretty intelligent guy, but I don’t understand this.”

Democrats proceeded carefully amid the escalating GOP tensions, framing Trump’s overtures as an opening to assert themselves more forcefully while acknowledging that Trump’s favor could be fleeting — and that their many in­trac­table differences are likely to remain.

“There aren’t permanent alliances. There aren’t governing philosophies. There’s day by day, seat-of-the-pants management,” Sen. Chris Murphy (D-Conn.) said in an interview.

By that measure, the Democrats have enjoyed two good days working with Trump.

On Wednesday, the president agreed to support legislation providing hurricane relief money in a package that also averts an imminent shutdown of the federal government and raises its borrowing limit for three months. The deal gives Democrats leverage to play a role in negotiations over several big-ticket items at the end of the year, including efforts to pass a law allowing undocumented immigrants brought to this country as children to remain here legally.

And on Thursday, Trump talked up the possibility of permanently removing the requirement that Congress repeatedly raise the nation’s borrowing limit. It was an idea he had discussed with Senate Minority Leader Charles E. Schumer (D-N.Y.) a day earlier, according to three people familiar with the discussion. The idea is opposed by many Republicans, including House Speaker Paul D. Ryan (R-Wis.), who see the imposition of a debt limit as a check on government spending.

Also Thursday, Trump tweeted that young undocumented immigrants currently protected by an Obama-era executive order known as Deferred Action for Childhood Arrivals do not need to worry about his administration acting against them for the next six months. The tweet followed the White House’s announcement this week that the program will be rescinded in six months.

It followed a request from House Minority Leader Nancy Pelosi (D-Calif.) — and was a striking move from Trump, who has largely ignored counsel of his own party’s leaders when it comes to his controversial social media habits, and who has rarely if ever communicated with Democrats about messaging.

"For all of those (DACA) that are concerned about your status during the 6 month period, you have nothing to worry about — No action!" the president tweeted from his personal account.

Said Pelosi at a subsequent news conference: “This is what I asked the president to do and, boom boom boom, the tweet appeared.”

The comity between the White House and Democrats sparked easy passage Thursday of a Hurricane Harvey relief package that allocates $15.25 billion in disaster aid and also raises the debt ceiling and keeps the government open until Dec. 8. The Senate approved the measure 80 to 17 as part of the pact between Trump, Schumer and Pelosi, sending it back to the House for final approval.

Democrats see the dynamics in Washington as newly fluid and potentially in their favor on a host of issues. In addition to pressing for new protections for undocumented immigrants, Democrats hope to water down GOP plans for tax policy and thwart a bevy of federal budget cuts proposed by Republicans.

Even so, some suggested caution about Trump’s sudden cooperation with them. They warned that the president’s unpredictability makes him a dangerous ally.

“Take advantage of it — but do it with the full knowledge that Trump will be calling, you know, Chuck Schumer names on Twitter within the fortnight,” Murphy said.

Interviews with multiple GOP senators and aides on Thursday, meanwhile, revealed that a sense of helplessness has gripped Republicans in the upper chamber after Trump openly flouted their plans.

“It’s just been jarring,” said one GOP Senate aide. The aide said that at the start of the week, there was a sense of confidence that White House officials were on the same page as Capitol Hill Republicans on the debt ceiling and Harvey aid negotiations.

But Trump ignored the guidance of those planning conversations.

Congressional Republican leaders didn’t want to give Democrats new leverage in December and have been under pressure from conservative rank and file to avoid more than one vote on the debt ceiling before next year’s midterm elections — only to be undercut by Trump.

Numerous members and aides predicted that the bill would fail to gain support from a majority of House Republicans, though given the wide support from Democrats, none thought it would ultimately fail.

Among those complaining the loudest were Texas lawmakers, who met as a bipartisan group at a lunch Thursday, with Texas Gov. Greg Abbott calling in and urging them to support the federal aid bill. Several conservatives in the area affected by Harvey said they expected to take their first-ever vote in favor of a debt-ceiling hike to advance Harvey aid.

“My fear is we set a bad precedent here, that you just load it up with other stuff,” said Rep. Blake Farenthold (R-Tex.), who represents the area where Harvey first made landfall. “This is what’s wrong in Washington: They pile stuff together so you have to weigh the good versus the bad rather than give every issue individual consideration. That’s the part of living in the swamp I don’t like.”

The chairman of the conservative Republican Study Committee objected to the agreement in a letter to Ryan, while Sen. Ben Sasse (R-Neb.) proposed an amendment to pass relief for Harvey victims as a stand-alone bill in the upper chamber, decoupled from debates over federal spending and the debt ceiling. The amendment did not advance.

At the White House, Trump was asked by a reporter about abolishing the congressional process for raising the debt ceiling. He replied that “there are lots of good reasons” to do it.

“It could be discussed,” Trump said. “For many years, people have been talking about getting rid of [the] debt ceiling altogether.” He confirmed during the exchange with reporters that the issue was discussed during his meeting with congressional leaders on Wednesday.

Trump and Schumer discussed the idea Wednesday in the Oval Office. The two, along with Pelosi, agreed to work together over the next several months to try to finalize a plan by December, which would need congressional approval.

One individual who spoke on the condition of anonymity to describe a private talk described it as a “gentlemen’s agreement.”

The U.S. government spends more money than it brings in through taxes and fees, and it covers that gap by issuing debt to borrow money. The government can borrow money only up to a certain limit, known as the debt limit or the debt ceiling. The government routinely bumps up against this ceiling, requiring Congress to raise it again and again. These votes are often politicized and can cause panic among investors.

Some Republicans labored to put a positive spin on what has been a politically startling couple of days for the GOP on Capitol Hill.

“In my opinion, we’re not going to shut down the government. That’s a plus,” said Sen. Dean Heller (R-Nev.), a moderate who is up for reelection and whom Trump threatened to campaign against over the summer. “And we’re going to take care of people in Texas — I think that’s a good thing.”

Other Republicans resorted to wishful thinking when it comes to Trump’s hostility to Heller and other Republicans — as well as his embrace of some vulnerable Democrats up for reelection in 2018, including Sen. Heidi Heitkamp (D-N.D.), whom he invited to ride with him on Air Force One on Wednesday.

“There’s going to be a little bit of sparring going on,” said Sen. John Cornyn (Tex.), the Senate’s ­second-ranking Republican. “But hopefully the president will recognize it’s in his best political interest to have as many Republicans in the Senate” as possible.

Ashley Parker, Kelsey Snell, Jenna Johnson, David Nakamura, Damian Paletta and Elise Viebeck contributed to this report.