WICHITA, Kan. — Congressional Republicans knew next year’s election could prove difficult, as the first midterm campaigns for the party controlling the White House often are. But not until a few days ago would they have believed that their immediate challenge would be hanging onto a House seat they have controlled for over two decades, in a district that President Trump carried by 27 points and that just happens to be home to that most nefarious of liberal boogeyman: Koch Industries.

Yet that is exactly what has happened since last week, when the House Republican campaign committee received a poll showing its candidate here in south-central Kansas winning by only single digits. Rushing to save the seat vacated by Mike Pompeo, now the C.I.A. director, before a special election on Tuesday, Republicans blasted out automated phone calls from Mr. Trump, hastily crafted an ad attacking the Democratic candidate on abortion, and dispatched Senator Ted Cruz of Texas for an 11th-hour rally on Monday afternoon with their own nominee.

“Our enemy right now is complacency,” Mr. Cruz told a lightly filled airplane hangar, picking up where he left off from his own presidential campaign last year. But this time, he was on a Republican rescue mission for Ron Estes, a House candidate.

As Kansas’ state treasurer, the mild-mannered Mr. Estes, an engineer by trade, has twice been on a statewide ballot. And he was initially not expected to have any difficulty keeping the seat in Republican hands in the race against a political newcomer, James Thompson, a Wichita civil rights lawyer.