And Mr. Bishop returned the favor. Claiming victory, he called Mr. Trump “the greatest fighter ever to occupy the White House” and told supporters that the president put “himself on the line for this race.”

Mr. McCready, appearing before supporters at a Charlotte hotel on Tuesday night, with his wife Laura at his side, offered his support to Mr. Bishop and invoked his campaign slogan, “country before party.”

“This was never a campaign about partisanship,” Mr. McCready said. “This was always a campaign about values. And we rallied together around the idea that as Americans we are all in this together. We may not have won this campaign, but that does not mean that we were wrong.”

In Washington, Mr. Bishop’s victory was not seen by Republicans as appreciably improving their chances of winning the House back in 2020. Indeed, his win came only after outside Republican groups poured over $5 million into the district.

G.O.P. strategists on Tuesday night said the race was eerily reminiscent of the other, nail-bitingly close special elections in the first year of the Trump presidency, when the party barely hung onto a handful of House seats that in previous years they carried with ease. Those too-close-for-comfort victories, in districts from Kansas and Montana to Georgia and South Carolina, were ominous signs for Republicans ahead of a 2018 midterm election where they lost the House.

And while Republican officials said a loss in North Carolina would have accelerated the trickle of G.O.P. lawmakers retiring, they were skeptical a narrow win would stop the trend entirely given the difficulty of running for re-election with an unpopular president on top of the ticket.