Voters in Kansas’ 4th Congressional District headed to the polls on Tuesday in an unexpectedly close race. And going into the day, there appeared to be a chance they would send President Donald Trump a rebuke in the first federal election since he won the White House in November.

In the end, Ron Estes, the Republican state treasurer defeated Democrat James Thompson, but early voting numbers showed more enthusiasm than usual among Democrats. Perhaps emboldened by this as the election approached, Thompson openly embraced support from a group that Sen. Bernie Sanders (I-Vt.) backs.

Conceding defeat, Thompson vowed from the stage that he would run against Estes again in 2018.

The contest was over the seat formerly held by Mike Pompeo, the tea party congressman Trump picked to run the CIA. Republicans have a considerable advantage in the district, which is home to Koch Industries, as Pompeo was re-elected by over 31 points in November.

Despite the assumed GOP advantage, Thompson, a civil rights attorney and Army veteran, had raised about $240,000 in small donations, much of which came in the waning days of the race.

Mark Reinstein via Getty Images Democrat James Thompson could pull off an upset.

National leaders from both parties have taken note, indicating the closeness and urgency of the race. After weeks of ignoring the surging Democratic enthusiasm in the district, the Democratic Congressional Campaign Committee on Monday gave Thompson a last-minute boost, making live calls to voters on his behalf.

The Democratic National Committee also recorded last-minute robocalls, and on Tuesday morning, party Chairman Tom Perez urged Democratic voters to go to the polls, tweeting a link to Thompson’s campaign website.

Polls are open in Kansas' 4th district—it's time to get out and vote for @JamesThompsonKS. Find out where: https://t.co/DOgwhqXdVj pic.twitter.com/VWRNlhzRuk — Tom Perez (@TomPerez) April 11, 2017

Republicans dispatched high profile surrogates including Vice President Mike Pence and Sen. Ted Cruz (R-Texas) and spent nearly $120,000 in the final days of the campaign, signaling how scared they were in a race that should have never even been close. Trump himself even recorded a phone call for Estes at the last minute and tweeted his support on Tuesday morning.

Ron Estes is running TODAY for Congress in the Great State of Kansas. A wonderful guy, I need his help on Healthcare & Tax Cuts (Reform). — Donald J. Trump (@realDonaldTrump) April 11, 2017

Trump goes full Trump in his robocall for Ron Estes in #ks04. Here's a transcript: pic.twitter.com/hCazA0unCN — Alexis Levinson (@alexis_levinson) April 10, 2017

Last week, before the GOP intervention, internal polling showed Estes with only a single-digit lead, The New York Times reported on Monday.

Thompson told The Huffington Post in an interview over the weekend that even if he lost, he would still consider the race a victory for Democrats because it shows that they can make Republican strongholds competitive.

And Democratic officials, who initially saw the race as a long shot, finally seem to be warming to that idea.

Attempting to explain their initial reluctance to intervene, a DCCC official told HuffPost on Monday that its involvement would have been “extremely damaging” because the GOP would use it against Thompson. But the unexpected Democratic mobilization provoked a change in strategy.

“Now that the race is being nationalized, and the involvement of a national party committee can’t be used against him, we don’t want Thompson to go unprotected,” the official said, adding that the race provides an opportunity to test the party’s strategies for future elections.

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.

Richard Mendoza, a Wichita hair stylist, is a registered independent who typically votes Democratic, he said, but has voted independent or Republican in the past. He voted at his neighborhood church Tuesday morning, and said it was bustling. A surprisingly high number of his clients and other people he has spoken with also voted in the election, he said. “Quite a few people are getting more involved as far as resistance,” he said. “More people seem to be more knowledgeable of even these smaller elections.”

An aide to Perez noted that the DNC chairman has been in the job just a few weeks and took the lead of the DCCC in the Kansas race. But, the aide added, the closeness of the race makes the argument for a 50-state strategy, which both Perez and his opponent-turned-deputy-chair Keith Ellison ran on.

“Tom is working to rebuild the party so that we’re investing in all 50 states, and while he’s making progress, we’re not there yet after a month as DNC chair,” the Perez aide said. “In this instance, the DNC followed the lead of the local party and DCCC. But it showed us exactly the reason why Tom is looking to start a national coordinated table so that we’re bringing various voices to the table to talk strategically about opportunities to pick up seats and how we can all use our resources to help candidates up and down the ballot.”

The Kansas race is one of three special elections across the country where Democrats could win in places traditionally dominated by the GOP. In Georgia’s 6th Congressional District, early numbers look good for Jon Ossoff, a 30-year-old running for the seat once held by Newt Gingrich that Tom Price had vacated to become secretary of Health and Human Services.

In Montana, Democrats also have a chance of picking up the House seat vacated by Ryan Zinke, a Republican tapped by Trump to lead the Department of the Interior. Republicans are concerned enough they could lose that they’ve worked to block a mail-in voting effort that would increase turnout.

Around the country, a groundswell of Democratic activism has already begun to shape state-level special elections, with Democrats making gains in traditionally Republican areas.

This article has been updated with election results and details on DNC support for Thompson. Ryan Grim contributed reporting.