Last Tuesday’s elections were a mixed bag for Tea Party legislators, or what we might call libertarian Republicans. The bad news was Corey Stewart’s defeat of Nick Freitas in the Virginia Senate primary and Katie Arrington’s defeat of Congressman Mark Sanford in South Carolina. However, the GOP’s libertarian wing picked up wins by Eric Brakey, who prevailed for the Senate nomination in Maine, and Lee Bright, who qualified for a U.S. House runoff in South Carolina.

Still, questions have been raised about whether or not libertarians are even welcome in a Republican Party controlled by President Donald Trump. After all Trump is not exactly a champion of small or even limited government—and that’s putting it mildly. The Trump administration has championed policies that libertarians generally despise, such as increased tariffs, immigration restrictions, spending hikes, and preserving the current entitlements system. And the Trump movement’s embrace of nationalism certainly goes against the cosmopolitan ideals of many libertarians.

This has led some libertarians to conclude that Republicans just aren’t into them. Among those who think that way is Reason editor-at-large Matt Welch, who says the GOP is a lost cause:

Libertarian policy goals will still sometimes be met under Trump, some of them intentionally, some not. He will continue deregulating and appointing some good judges, may yet contribute to genuine peace on the Korean peninsula, and has proven surprisingly malleable on marijuana enforcement and prison reform. But as an organizing body, particularly anywhere near the levers of federal power, the GOP is an increasingly unreliable ally to libertarians.

It’s hard to disagree with that. The GOP under Trump is certainly not a party that values limited government. Then again, the GOP has rarely ever seemed to value limited government, at least when it’s in power.

But is all lost for libertarians? A closer look at the both the Freitas and Sanford losses reveals the answer is not a simple one.

In Virginia, Stewart picked up 44.9 percent of the vote to Freitas’s 43.1 percent, or a little more than a 5,000-vote difference. Stewart had run for statewide office two times previously and served as Donald Trump’s Virginia campaign manager until he was fired in October 2016. After losing the Republican primary for governor in 2017, he almost immediately began campaigning for the Senate. He had the highest name ID in the race.

Freitas, on the other hand, only began campaigning for Senate at the beginning of this year. He was a relatively unknown state house member before the campaign, and he spent only $355,749 compared to Stewart’s $680,505, according to Federal Election Commission records. Freitas was able to close the money gap with help of the Rand Paul-aligned America’s Liberty PAC, which spent $225,000 on TV ads, and Americans For Prosperity, which spent $137,283 on phone banking and digital ads.

But the outside money backing Freitas was a drop in the bucket given how large Virginia is. For example, in last year’s governor’s race, AFP spent millions against Democrat Ralph Northam and still lost. So given where both candidates started financially, this doesn’t seem like a catastrophic loss for libertarians. Indeed, Freitas nearly pulled it off despite his lower name recognition.

The margin of victory boiled down to the 10th Congressional District, which saw a primary battle between Congresswoman Barbara Comstock and Shak Hill. That race drove up numbers for Corey Stewart because he organized and worked in the district.

As for South Carolina, at first blush it seems even more devastating to libertarian Republicans. There, Arrington made her support for President Trump a major focus of her campaign and contrasted it to Sanford’s criticisms of Trump.

But a deeper look at the race tells a different story. The fact is that Arrington worked hard on the campaign trail while Sanford took his reelection for granted. The result was predictable, regardless of any Trump factor.

Arrington raised $611,073, including $408,300 of her own money, and spent $384,262. Sanford, on the other hand, spent $360,457 and only $166,287 on media. Sanford also had no campaign staff and over $1.5 million cash on hand as of the latest FEC filing.

These races don’t seem to amount to the repudiation of libertarian Republicans that others see. Still, it’s worth asking what lessons libertarians can learn to survive and thrive in the Trump era. The biggest one comes from Daniel McCarthy, who notes that libertarianism was a success in the GOP when it was anti-establishment:

These are lessons for libertarians to learn. They succeeded for seven years in Republican politics because they dared speak truths that others wished to ignore, truths about the futility of our foreign wars and the precariousness of our economy. But when another insurgent came along to speak those truths, and others, in even plainer and more urgent terms, the libertarian moment was past.

Those libertarians who have continued to “speak truth to power” are the ones who have thrived in the Trump era. Senator Rand Paul, Congressman Thomas Massie, Congressman Justin Amash, and libertarian leaners such as Senator Mike Lee and the House Freedom Caucus are flourishing because they’ve maintained their anti-establishment credentials. This is despite the fact that they have opposed and even criticized Trump at times.

Amash, who was targeted by Trump allies for a primary challenge, wound up running unopposed. Although he faces a tough general election battle, he is still favored to be reelected. Massie is all but certain to return to Congress.

Contrast their fates with another libertarian leaner and Trump critic, Senator Jeff Flake. Flake was forced to retire after it became clear he would be defeated in the primary by populist Kelli Ward, who herself has libertarian leanings.

Flake was a strong proponent of free trade and railed against pork barrel spending in the House of Representatives. He was not afraid to challenge his own party on those issues. But since being elected to the Senate in 2012, Flake had also become a consistent ally of the Republican establishment.

“Flake could have been opposed to President Trump and even been outspoken about it,” wrote conservative commentator Erick Erickson. “But he could not sell out his conservatism and then become an outspoken Trump critic. That is, however, what he chose to do.”

Libertarians can survive in the Trump era. After all, Trump’s destruction of the old GOP has given them space to operate. But libertarian Republicans must not forget their anti-establishment roots and they cannot take their election races for granted.

Kevin Boyd is a freelance writer. He has been published at The Federalist, IJ Review, the New York Observer, the Atlanta Journal-Constitution, and the National Interest. You can follow him on Twitter @TheKevinBoyd.