Mr. Grimm’s incumbent opponent, Dan Donovan, is viewed by most fellow Republicans as a broadly inoffensive, if establishment-minded steward of the office. He has spent the last several months conspicuously attaching himself to Mr. Trump as well, recently introducing legislation that would require the president’s portrait be displayed at every post office in America, and sprinkling even casual conversation with mentions of his ride last year on Air Force One.

“Coolest aircraft in the world,” Mr. Donovan, 61, said in an hourlong interview last week, demonstrating the plane’s layout with a lunch check and his wallet.

But Mr. Donovan is facing a man who seemed to intuit the merits of Mr. Trump’s defiant approach long before the 2016 election, taking its tenets to their logical extreme.

The president refused to release his tax returns; Mr. Grimm is following suit despite having served seven months in a federal prison for tax fraud.

The president has discussed revoking credentials from members of the news media; Mr. Grimm once threatened to throw a television reporter off a Capitol balcony and break him in half “like a boy.”

The president claims the investigations into his administration’s dealings with Russia are a “witch hunt.” Mr. Grimm’s guilty plea in the tax matter has not stopped him from arguing the same about his own prosecution on the campaign trail.

“I see it identical,” he said in an interview last week at Andrew’s Diner, near Staten Island’s southern shore.