HILTON HEAD, SC - MARCH 18: Rep. Mark Sanford (R-SC) waits for his introduction during a town hall meeting March 18, 2017 in Hilton Head, South Carolina. Protestors have been showing up in large numbers to congressional town hall meetings across the nation. (Photo by Sean Rayford/Getty Images)
CNN  — 

Republicans in Congress said the message came in loud and clear Tuesday night: Oppose President Donald Trump and it could cost you your seat.

Rep. Mark Sanford, a member of the conservative House Freedom Caucus who’s been outspoken against the President, suffered a stunning primary defeat in his South Carolina district Tuesday, just hours after Trump blasted the congressman on Twitter and publicly supported his opponent.

While there were some local factors at play in Sanford’s race, his loss was widely interpreted as a rebuke among GOP voters of lawmakers who march out of step with Trump.

“This is Trump’s party,” said Republican Sen. Jeff Flake, a fierce critic of the President who decided not to run for re-election in Arizona. “We’ve all felt it. It was reiterated last night. If you want to win a Republican primary, you can’t deviate much from the script. It’s the President’s script. You can’t criticize policy or behavior.”

The President was quick to take credit for Sanford’s loss Wednesday morning while praising the new GOP nominee, Katie Arrington.

“My political representatives didn’t want me to get involved in the Mark Sanford primary thinking that Sanford would easily win - but with a few hours left I felt that Katie was such a good candidate, and Sanford was so bad, I had to give it a shot. Congrats to Katie Arrington!” Trump tweeted.

The congressman and former governor had been sharply critical of Trump’s rhetoric and style, and he was one of the few Republicans who hammered Trump for not publicly releasing his tax returns.

It may have bit him in the end.

“I think it’s quite obvious that people don’t like, you know, when somebody’s overly critical of the President,” said Republican Rep. Adam Kinzinger of Illinois. “I thought Mark was very principled. But you know, it will be interesting to see what it comes down to ultimately.”

While Trump’s approval ratings nationwide hover in the 40s in recent polling, his approval rating within the Republican Party is sky high at over 70%.

Put simply, it’s a numbers game, said Rep. Chris Collins, a New York Republican. “With all politics being local, if you’re not on the same page as the President and 85%-90% of your base is, you can see where that could cause a problem.”

House Speaker Paul Ryan declined to draw a connection between Sanford’s criticism of Trump and his primary loss. Rather, he said, sometimes people just lose.

“It was a very close election. Some of our members have lost primaries. That’s just what happens in contested primaries,” he said at a news conference Wednesday.

Rep. Mark Meadows, a close ally of the President, is rarely short on words when talking to reporters, but on Wednesday he declined to weigh in on the President’s last-minute involvement in Sanford’s race or speculate on the congressman’s defeat.

RELATED: 2 names that explain why Republican politicians are afraid of criticizing Donald Trump

“I think that we serve at the pleasure of the people that we have the honor of serving,” he said. “Every two years we’re up for a vote … and I’m very cognizant of the fact that this is a temporary job.”

Still, to other members, Trump’s decision to rail against Sanford on a primary day demonstrated the consequences of publicly rejecting the President.

GOP Rep. Barry Loudermilk of Georgia argued that Republicans in Congress still have to call out the President when necessary, given the oversight role of the legislative branch. “But it tells us we need to bring a little more civility in how we actually do that.”

Loudermilk warned that going public with one’s disagreements, as Sanford did, is not the most effective approach. “I have some differences with the way we’re handling tariffs, but I haven’t gone out and aired those differences to the media first,” he said. “I go to the White House, and there’s been an open door and a dialogue going on.”

Rep. Bill Flores of Texas said Sanford’s tone “was way too aggressive” in how he criticized the President. Like Loudermilk, the congressman said he also prefers a more private strategy when discussing disagreements with the White House.

“I don’t think you stand on a street corner and throw rocks at the President,” he said. “I don’t think that’s appropriate.”

Sanford said Tuesday night that he was “neither for nor against Trump” but maintained that he bases his decisions and comments on his political values.

“It may cost me an election in this case,” he said. “But I stand by every one of those decisions to disagree with the President.”

CNN’s Ted Barrett, Tal Kopan, Eric Bradner and Ann Colwell contributed to this report.