WASHINGTON — A border wall perhaps isn’t the one President Trump should worry about. With his abrupt move to yank U.S. troops from Syria and provoke his Defense secretary’s resignation — both actions coming amid last week’s government shutdown drama — Trump has opened cracks in his wall of support among Senate Republicans.

And that wall is the one the president will need as his bulwark in the remainder of his term, should he come to be impeached by a House newly controlled by Democrats as of January, and then face trial in the Republican-majority Senate.

Public criticism from Trump allies including Sens. Lindsey Graham of South Carolina, Marco Rubio of Florida and especially Mitch McConnell of Kentucky, the Senate majority leader, telegraphed how shaken they were by Thursday’s news that James N. Mattis is resigning in protest as Pentagon chief. From the administration’s start, Republicans in the Senate and beyond have looked to Mattis to guard against Trump’s impulsive behavior.

Trump, however isolated and unrestrained he seems now, is still a long way from losing the 20 Republican senators it would take to remove him from office by a two-thirds vote after an impeachment trial. Also, he has seemed on the verge of losing backing in the past — before and after his election. The Senate has opposed him on occasion, most recently to penalize Saudi Arabia after the killing of a dissident U.S.-based journalist, even as Trump defended the country’s rulers.

But if Trump’s Senate fortress breaks, perhaps after incriminating findings of ongoing investigations, historians might look to last week as a turning point.

Col. James Carafano, who was a top advisor on Trump’s postelection transition team and has rarely criticized him, called the Syria decision, which precipitated Mattis’ resignation — followed by that of senior Middle East envoy Brett McGurk — “a self-inflicted wound.” He said the White House had “done a poor job” in explaining how withdrawing all troops from Syria and halving the U.S. military presence in Afghanistan, as Trump is also suggesting, could make this country safer.

Rubio, who had forged a tenuous peace with Trump after trading personal insults in their competition for the 2016 Republican presidential nomination, tweeted that Mattis’ resignation letter “makes it abundantly clear that we are headed towards a series of grave policy errors which will endanger our nation, damage our alliances & empower our adversaries.”

The rare public rebukes of Trump come after two years in which congressional Republicans have mostly vented privately about the impetuous president. They come amid growing consensus in Washington that the president will need all his survival skills in the next year to weather whatever special counsel Robert S. Mueller III reveals in his looming report on Russian interference in the 2016 election, as well as the outcome of separate legal proceedings, investigations by newly empowered House Democrats and perhaps an economic downturn.

Republicans privately are as worried as they’ve ever been. “Think of Trump as sitting on an island,” said a top aide to a pro-Trump senator who requested anonymity to reflect GOP senators’ conversations. “Every story like Mattis, Syria, shutdown is like a wave that erodes a little more of the beach. How much land is going to be left when the Mueller tidal wave hits?”

The week began with a president who has branded himself as a master deal-maker reversing his position daily on the essential government-funding bill, to congressional Republicans’ open consternation, even as he remained on the sidelines of negotiations.

He veered from threatening a partial government shutdown unless he got $5 billion more for a wall to retreating from that demand and then, on Thursday, renewing the threat after the Senate — acting with what it thought was the White House’s blessing — unanimously approved a temporary government-funding bill without wall money. Trump then allied with House Republicans to pass a bill to his liking, though it was doomed in the Senate.

Trump’s changing stance on the wall fight reflected his fear of losing his base of support on the hard right, which in turn sustains his backing from Republicans in Congress. He also was reacting to conservative media figures including Rush Limbaugh and Ann Coulter, who warned that he would forever lose his supporters if he capitulated on the wall; his advisor Stephen Miller, who has spent his career on the hard-line fringe of the immigration debate; and House Freedom Caucus members led by Rep. Mark Meadows of North Carolina, who spoiled for a showdown with Democrats.

Juxtaposed with his sudden decisions on Syria and Afghanistan, made over the objections of Mattis, McGurk and the national security team, Trump’s budget brinkmanship underscored just whom he listens to and whom he does not. And that reality was unnerving to Republicans in the Senate.

Many of them, and others in the GOP establishment, support Trump reluctantly as a matter of practical politics — he remains overwhelmingly popular with the party’s voters — and because he is the vehicle to achieve their goals including tax cuts, deregulation and confirmation of conservative judges.

But some do not support significant parts of Trump’s agenda, notably his trade protectionism, his nationalism, his coziness with autocrats over allies — and his commitment to a border wall. Though other Trump advisors with Senate support have left, Republicans especially looked to Mattis as a check on Trump in the most consequential decisions of war and peace.

Mattis, with his stunningly candid resignation letter, publicly confirmed that he had failed with Trump. He implicitly criticized the president’s mistreatment of allies and his indulgence of adversaries Russia and China, and concluded that he’d leave by the end of February.

“Because you have the right to have a Secretary of Defense whose views are better aligned with yours on these and other subjects, I believe it is right for me to step down from my position,” Mattis wrote.

John A. Farrell, author of “Richard Nixon: The Life,” said after the Mattis news, “The national intelligence establishment has been warning us and criticizing Trump for two years. He could always say they were Obama appointees. Now this is his premier appointee, the one person that everybody felt was keeping us safe from our worst nightmares.”

McConnell, normally careful in his words, endorsed Mattis’ resignation letter, calling himself “particularly distressed that he is resigning due to sharp differences with the president on these and other key aspects of America’s global leadership.”

Graham, who has become one of Trump’s closest Senate allies, lashed out at the decision to withdraw from Syria, comparing Trump to his predecessor.

“I thought President Obama was a nice man and was a bad general,” Graham said, repeating his criticism that Obama overruled his military advisors. “I don’t think Gen. Trump is going to be any better than Gen. Obama.”

In January, Senate Republicans will return to confront a calendar packed with confirmation hearings for Cabinet nominees. That is the cumulative toll of the dysfunction within the White House that now has some GOP lawmakers contemplating breaking from Trump, and wondering whether they might be better off with Vice President Mike Pence taking over.

Though Democratic leaders deny that Trump’s impeachment is under consideration, barring some findings that force the issue, Michael Steel, a former advisor to GOP leaders in Congress, called Trump’s impeachment by a Democratic-led House next year “a foregone conclusion.”

Steel said Trump would probably escape removal from office, given the GOP Senate majority. “At the same time,” he added, “rising frustration — combined with continued investigation and perhaps a slowing economy — could eventually change that calculus.”