(Jenny Starrs/The Washington Post)

Republicans fended off a surprising Democratic challenge on Tuesday in the first special election of the year for a House seat vacated by a Republican lawmaker who became part of President Trump’s administration.

Ron Estes, the GOP state treasurer, was buoyed by an 11th-hour intervention from national Republicans, Vice President Pence and Trump himself in his bid to retain the seat of former congressman Mike Pompeo, who is now the CIA director. In a victory speech, Estes told voters he’d “repeal and replace Obamacare” and fight for a balanced-budget amendment to the Constitution.

“Republicans emerged victorious in the first contested special election of the 2018 cycle,” said National Republican Congressional Committee chairman Steve Stivers, a congressman from Ohio.

With 99 percent of ballots counted, Estes led Democrat James Thompson, a lawyer making his first bid for office, by 8 points. Last year, Pompeo won reelection by 31 points in a race Democrats did not seriously contest.

“I probably shouldn’t say this, Mr. Estes did not beat us,” said Thompson at his election-night party. “It took a president of the United States, the vice president, the speaker of the House, a senator coming into our state, and a bunch of lies to try and drum up a vote.”

Democrat James Thompson, a candidate for Kansas' 4th Congressional District, speaks during a debate in Wichita, Kan. (Bo Rader/AP)

Kansas Republicans’ resilience dashed Democratic hopes — which surged over the weekend — of slicing into the majority of House Speaker Paul D. Ryan (R-Wis.). It also may dampen that party’s hopes of performing well in the three House seats vacated by Republicans who joined the Trump administration — most significantly in Georgia, where Democrat Jon Ossoff is leading in the April 18 contest to replace Health and Human Services Secretary Tom Price against a crowded field of GOP candidates.

Yet holding the 4th Congressional District — which Trump captured by 27 points in November, and is the home to Koch Industries — took more work, and money, than Republicans had expected. Thompson easily won voters who cast their ballots early and was poised to carry Wichita’s Sedgwick County, which Trump won by 18 points.

In the campaign’s final weekend, the NRCC spent close to $100,000 on the race, and the GOP-allied Congressional Leadership Fund super PAC paid for tens of thousands of get-out-the-vote phone calls. President Trump even recorded a call for the Republican and sent an Election Day tweet calling Estes a “wonderful guy” who would help him on “Healthcare & Tax Cuts (Reform).”

The victory helped House Republicans retain a 23-seat advantage over Democrats, despite entering the two-week recess short on their major legislative goals. Estes did not focus on Trump in his race, and though he is expected to be a reliable vote for Republicans in the House — he said on Monday he would not join either right-wing or moderate caucuses — he had criticized the GOP health-care bill that was pulled before the congressional recess.

Thompson, a 46-year-old U.S. Army veteran who had caucused for Bernie Sanders, fought a stronger-than-expected race that Democrats said would put more races on the map in 2018.

But progressives were critical of the party for letting the race play out without a major investment. “We lose when we don’t fight, period,” said Neil Sroka, a spokesman for the progressive group Democracy for America, in a tweet.

Without the boogeyman of the Obama administration, and without the threat of Hillary Clinton picking a judge to fill an open Supreme Court seat, Republicans resorted to arguing that Thompson would use constituents’ tax money to fund abortions. Until it finally spent some money on get-out-the-vote calls, the DCCC stayed away for fear that it would nationalize the race.

The contest began with Pompeo’s Jan. 23 departure from Congress, which attracted little national attention until the start of April. The Cook Political Report marked the race as “safe” for Republicans, downgrading the party’s chances only after the final weekend’s scramble.

Inside the district, however, both parties saw early potential for an upset. Estes, a businessman who entered politics in 2004, had only ever won landslides in the 4th District for state office.

But in Topeka, the state capital, he became associated with a Republican governing team that has presided over a weak economic recovery and a series of budget deficits. Democrats — and increasingly, voters — came to blame Gov. Sam Brownback’s supply-side tax cuts, which ate into the state’s revenue.

In 2016, as Republicans won across the country, the party lost ground in Kansas. Democrats gained 12 seats in the state House and one seat in the state Senate, after moderate anti-Brownback Republicans defeated conservatives in a series of primaries. On Election Day, Trump carried the 4th District easily — but Republicans lost three of their party’s state House seats.

The Democratic Party, meanwhile, underwent an evolution of its own. Sanders crushed Hillary Clinton here in the 2016 caucuses, and many Sanders activists stayed inside the party to win leadership positions. When Pompeo’s seat opened, former state treasurer Dennis McKinney — who was defeated in 2010 by Estes — was initially seen as the Democratic front-runner. But the antiabortion McKinney lost a tight party contest to the pro-abortion rights, economically populist Thompson.

While Estes was tied up in Topeka working on the controversial state budget, Thompson barnstormed the district.

In the final 24 hours of the race, the Democrat attended a Seder with Jewish voters, recorded a “thank you” video for volunteers, shook hands at a breakfast for Learjet retirees, and (through a translator) sat for an interview with Wichita’s Spanish-language radio station. Estes rallied with Sen. Ted Cruz (R-Tex.) and the national political director of the Chamber of Commerce, then cast his vote.