Mr. MacArthur acknowledges the challenge he faces and points to the layout of his district to illustrate the political dynamics at play.

“I try to remind people that I have to straddle the Pine Barrens,” he said in an interview. “The 1.1-million-acre Pine Barrens that runs through the middle of the state divides my district in half. On the one side is Ocean County, where Trump won by 93,000 votes. And on the other side is Burlington County where he lost by 16 percentage points. I have to straddle that.”

On a swing through the heavily Republican oceanside town of Toms River, Mr. MacArthur interspersed his allegiance to the president with evidence that he is not simply a rubber stamp for Mr. Trump or the party.

There was “something malign in the bosom of the Democratic Party,’’ Mr. MacArthur said starkly, while adding that nevertheless, “I probably spend most of my time working with Democrats.”

Mr. MacArthur voted in favor of a bill that required all states to recognize concealed-carry gun permits from other states. But, he explained, the legislation also contained a provision opposed by the National Rifle Association that requires a more rigorous background-check system. “We don’t have that today,’’ he said. “That is more dangerous.”

And though he has supported much of Mr. Trump’s tariff policies, he said he successfully lobbied the administration to drop one tariff that would have harmed a chemical company in Burlington County.

“I’m not saying that the president’s popularity has no impact on my race,” Mr. MacArthur said. “Of course it does. But I can look people in the eye and say I work with the president when I can.”