A last-minute intervention by national Republicans in one of the reddest districts in America was enough to stave off what would have been a crushing upset Tuesday in Kansas’s 4th Congressional District ― but the unexpectedly close race still portends major problems for Republicans in 2018.

State Treasurer Ron Estes (R) beat Bernie Sanders-backed Democrat James Thompson in a Kansas congressional special election that became close in the final weeks of the campaign. Estes ended up taking 52.5 percent of the vote to Thompson’s 45.7 percent.

By the numbers, the race in Kansas shouldn’t have been close. Rep. Mike Pompeo, a tea party Republican picked to lead the CIA, was re-elected to his seat by more than 30 points in November in a reliably conservative district that is home to Koch Industries.

But in the middle of last week Republicans began circulating an internal poll showing Thompson trailing by just 1 point, and the national party quickly invested nearly $120,000 to back up Estes. President Donald Trump recorded a robocall on his behalf and tweeted about the race Tuesday morning, and Vice President Mike Pence and Sen. Ted Cruz (R-Texas) were dispatched to shore up support.

The infusion of cash was a signal to Democrats that, all of a sudden, the race was competitive. Yet the Democratic Party stayed out of the race until the campaign’s final days, when the Democratic National Committee and Democratic Congressional Campaign Committee began making calls on his behalf.

In an interview with The Huffington Post over the weekend, Thompson said the national party stayed away because they had concluded early on he couldn’t win. “A lot of people don’t want to be proven wrong,” he said.

Washington Democrats, for their part, argue that had they jumped into the race earlier, it would have become “nationalized” ― meaning voters would retreat to their partisan corners and Thompson would have been sunk. But even if that’s true, their reluctance to match the Republican ad buy has left grassroots Democrats furious. Even without the party involved, independent activists sent more than $200,000 to Thompson in the closing days of the race.

That Thompson made the race competitive at all is a testament to the strength of the opposition to Trump. The grassroots Democratic resurgence can be traced back to the Women’s March the day after Trump’s inauguration, a rally in Washington that was replicated in towns and cities across the country, and drew some 5 million people into the streets ― all of it done independently of the Democratic Party party. When Trump implemented his Muslim ban shortly after, protesters flooded airports, again organically, but this time joined by a handful of Democratic politicians who were seeing the resistance for the sustained movement that it was.

Elected Democrats responded by rallying in a largely unified way against Trump’s nominees and his agenda on Capitol Hill, wary of winding up on the wrong end of the energized base. When Trump and House Speaker Paul Ryan pushed forward with a repeal of the Affordable Care Act, Republican members of Congress heard an outpouring of opposition, much of it channeled by local Indivisible groups, which hadn’t existed before the election. While Trump has been told by his allies on Capitol Hill that it was extreme conservatives in the Freedom Caucus who sunk repeal, in reality it was done in by moderate Republicans who felt heat back home.

In February, Democratic voters in Delaware swarmed to the polls in a critical special election to claim the state senate, and donors began pumping millions of dollars in small contributions to Jon Ossoff, a Democrat running in a special election in suburban Atlanta to replace Tom Price.

If there is another winner in Tuesday’s race in Kansas, it’s the website DailyKos. While nobody outside the district spotted the race as competitive until recently, Kos included, the site kicked into high gear when it decided to turn on the financial spigot. Its members donated more than $160,000 to Thompson’s campaign in just a few short days.

David Nir, political director for DailyKos, said that the site had been monitoring the race from the moment it began, but didn’t take it seriously until last Wednesday, when news filtered out that national Republicans had thrown more than $100,000 into the race. That kind of investment is only made under extreme duress, and it sent a signal that the race was suddenly competitive. Nir said he and the Kos team quickly decided to make an endorsement and get an Act Blue fundraising page launched, but first he called the Thompson campaign to ask if the money could actually be put to use.

The campaign said that, yes, it could expand its ad buy, broaden its get-out-the-vote operation and fully fund its voter protection unit, the team of lawyers that monitors voting irregularities. With that assurance made, Kos went live with its fundraising page and pushed it to its email list of 3 million members.

Asked if there was any way that people outside the district, including Kos, could have known sooner that the election was competitive, Nir said he thought it wasn’t possible, other than going on pure intuition.

On Sunday, Thompson said that regardless of the outcome of the race, he felt he had already won because he had shown that Democrats could make a Republican district competitive by running on an unapologetically progressive platform.

The Kansas election, said Thompson, was as much a referendum on Gov. Sam Brownback as it was on Trump. In that sense it was a referendum on extreme conservatism itself, or at least Brownback’s version of it, said Jeff Emerson, an attorney in Wichita. “The general population recognizes this has certainly not worked well,” Emerson said. “Voters are just generally more aware of cause and effect here than they were three to five years ago.”

He said he voted early for Thompson. He typically votes Democratic, he said, but is registered as a Republican, like many others in the city, so that he can vote in Republican primaries for judicial elections. Often, Democrats don’t bother to put up a candidate. “There’s a lot of people in Wichita who do that so they have some voice in who emerges out of the primary,” he said.

The DNC, however, has figured out Emerson’s leanings, and calls him regularly for donations. “I can’t tell you how many times the DNC has called me for money, and my stock answer is, tell me how much money you’re putting into Kansas politics, and I get a deer-in-the-headlights silence,” he said. But he added he was heartened to see the last-minute effort the national party put in.

The Kansas race, the first federal race since Trump’s November victory, was one of a number of elections across the country that drew national interest as a bellwether of whether the early furor and opposition to Trump’s administration could translate to political gains. At the state level, Democratic activism has already helped Democrats do well in areas where Republicans have traditionally performed well.

Democrats now turn to Georgia and Montana, where they’re looking to flip Republican seats in special elections. Thirty-year-old Ossoff is running a close campaign in Georgia’s 6th District for a seat long held by Republicans, including former House Speaker Newt Gingrich.

In Montana, folk singer Rob Quist is running for the seat given up by Ryan Zinke, now secretary of the interior, and appears to have caused early rumblings of Democratic enthusiasm.