Trump won this Kansas House district by 27 points. A Republican just won it by single digits.

GOP congressional candidate in the 4th district Ron Estes votes at Holy Cross Lutheran Church. At right is his wife, Susan Estes. (Photo: Jaime Green/The Wichita Eagle via AP)
GOP congressional candidate in the 4th district Ron Estes votes at Holy Cross Lutheran Church. At right is his wife, Susan Estes. (Photo: Jaime Green/The Wichita Eagle via AP)

A ruby-red Republican district in Kansas where Donald Trump trounced Hillary Clinton just five months ago stayed in GOP hands Tuesday night even as Democrats dramatically closed the margin in the state — an outcome sure to send shivers through Republicans facing reelection in 2018 in less favorable districts.

With more than 99 percent of the votes counted, state Treasurer Ron Estes was declared the winner of the first congressional election since Donald Trump won the White House, taking more than 53 percent of the vote. The special election in Kansas’ Fourth Congressional District had pitted Estes against civil rights attorney and army veteran James Thompson for the seat vacated by Mike Pompeo, now Trump’s CIA director. Libertarian Chris Rockhold also ran.

Thompson won more than 45 percent of the vote — a percentage more than 15 points higher than that garnered by the Democrat who ran in the district last November.

Kansas is not a swing state in presidential elections, and the last time a Democrat won its Fourth Congressional District was 1992. This past fall, Pompeo bested his Democratic rival by 31 percentage points, and Trump won the district by a 27 percent margin of victory.

Thompson’s under-the-radar campaign in the district proved to have surprising momentum, thanks to disillusionment in the state with the policies of GOP Gov. Sam Brownback and Thompson’s own authentic-seeming message of helping the working class.

His ability to close the margin forced national Republicans to pitch in to bolster Estes over the final weeks of the race in what should have been an easy Republican seat to hold.

“Mr. Estes did not beat us. It took a president of the United States, a vice president, the speaker of the House, a senator coming into our state, and a bunch of lies to try to drum up the vote,” Thompson said after his loss.

Kansas has been going through a wrenching political period after a Republican experiment with massive tax cuts led to budgetary shortfalls, which are projected to reach more than $1 billion by the middle of 2019. That has transformed the normal political conversation in the state and led even Republican legislators to back tax increases in an effort to fix the state revenue gap, though their efforts have yet to succeed. The trouble with taxes led Kansas Democrats and GOP moderates to make significant gains in the state Legislature last fall, at the same time Trump was elected, though both remain in GOP hands.

This more moderate Kansas state Legislature voted to expand Medicaid under the Affordable Care Act shortly after the failure of Trump’s Obamacare repeal efforts last month. GOP Gov. Sam Brownback vetoed the expansion, and the GOP-controlled Kansas House narrowly upheld his veto.

Democrat James Thompson gets a hug from supporter Djuan Wash at the Murdock Theatre in Wichita, Kan., Tuesday, April, 11, 2017. (Photo: Travis Heying/The Wichita Eagle via AP)
Democrat James Thompson gets a hug from supporter Djuan Wash at the Murdock Theatre in Wichita, Kan., Tuesday, April, 11, 2017. (Photo: Travis Heying/The Wichita Eagle via AP)

The Estes campaign itself did not generate particular enthusiasm and came in for some light mockery over an ad featuring him in chest-high waders in a literal swamp, promising to drain the metaphorical one in Washington. His ads have focused more on reining in Washington excesses, while Thompson’s have focused on biography and the struggle to get out of poverty and to live as a member of the working class in Kansas.

National Republicans piled in to the race to save the seat after internal polling showed the margin of the contest to be too close for comfort. “I am personally reaching out to you today to help strengthen our House majority by electing Ron Estes in Kansas’ Fourth Congressional District,” House Speaker Paul Ryan wrote in an email appeal. “As a friend of Ron’s and as House Speaker, I can tell you that this is one of the most important House races in the country.”

Sen. Ted Cruz, R-Texas, stumped for Estes on Monday in Wichita, urging voters to take nine others to the polls with them and warning, “Our enemy right now is complacency.” Cruz, a former 2016 presidential candidate, beat Trump in the Kansas Republican presidential primary caucus last year.

Vice President Mike Pence recorded a robocall over the weekend. So did President Trump, speaking out on a one-minute, five-second robocall that went out to tens of thousands of likely GOP voters Monday.

“I have something big to tell you. … On Tuesday, Republican Ron Estes needs your vote and needs it badly,” Trump said in the recording.

“Ron is a conservative leader who’s going to work with me to make America great again. We’re going to do things really great for our country. Our country needs help. Ron is going to be helping us, big league. … This is an important election.”

On Tuesday, he followed up with a tweet:

Though Trump is polling at roughly 40 percent nationally, his support remains strong in solidly Republican areas as well as among party members.

“People here still like Trump,” Thompson told the Washington Post. “It’s not been a referendum on him. It’s a referendum on the failed Republican leadership in the state. People don’t want these policies taken to the national level.”

That hasn’t stopped Thompson from allying himself with the anti-Trump resistance in no uncertain terms, tweeting out the hashtag #resistance in thanks to the local anti-Trump Indivisible group that has been organizing on his behalf.

Thompson’s message has focused on working-class families, veterans, the Constitution and the need for a political change.

An earlier, much less high-powered Trump team effort to buoy a candidate in the state fell flat in February, when White House-backed Alan Cobb failed to make it out of the GOP special election primary. Sam Clovis, the one-time Trump campaign co-chair, had sent a letter supporting Cobb to the 126 state party delegates who would pick a candidate, and Trump social media guru Dan Scavino tweeted on his behalf. Cobb also had strong ties to the Kochs, as the former Kansas director of Americans for Prosperity and a one-time lobbyist for Koch Industries.

In the end, Estes’ long tenure in the district and history of winning office statewide made the difference.

Early voter turnout was low but had a disproportionately high share of Democrats, given the district’s historic GOP tilt, and helped lift Thompson on Election Day.

Thompson raised a quarter of a million dollars in the final days of the race, much of it in small-dollar donations via liberal fundraising sites.

On Monday, the Democratic Congressional Campaign Committee, which had been staying away from the contest, entered the race to do last-minute live calls to 25,000 households.

Read more from Yahoo News: