Mr. Trump’s push for Mr. Bishop is part of a wider administration effort on his behalf that also included a visit on Monday to the other end of the district by Vice President Mike Pence. Both Democrats and Republicans have poured millions of dollars into the race.

The special election was called after the Republican candidate in the 2018 election, Mark Harris, was embroiled in an illegal vote-harvesting scandal. Last November, North Carolina officials refused to certify the results of the race between Mr. McCready and Mr. Harris because of “irregularities” in the balloting.

A monthslong investigation concluded in February that the Republicans had engaged in an illegal voter-turnout effort, prompting officials to overturn the results and set a new election. Mr. Harris withdrew from the contest, setting off a crowded Republican primary race that Mr. Bishop won. So in effect, Mr. McCready has been campaigning for the seat for 27 straight months.

That the conservative district is up for grabs at all is a concern for Republicans, and the president’s appearance in the state on the eve of the election highlighted that. Mr. Trump carried North Carolina by less than four points in 2016.

“If North Carolina suburbs are transitioning from a solid Republican base to a more ‘competitive’ region,” Mike Bitzer, a Catawba College professor, wrote in an election preview, “then the Ninth Congressional District may be a potential test case for whether this gives any indication as to the reaction by suburban voters to the president’s actions over the past few weeks.”

After a week in which Mr. Trump publicly obsessed over news media criticism about his inaccurate claims about Hurricane Dorian’s potential effect and feuded with critics like the actress Debra Messing and the mayor of London, the president delivered a relatively disciplined campaign message.

In remarks that lasted about 90 minutes, Mr. Trump, with an eye toward November 2020, mostly boasted about his own record, touching on issues like health care and the opioid epidemic. At the mention of his proposed southwestern border wall, the audience chanted, “Build the wall! Build the wall.”