Corey Stewart at a February campaign stop at a shooting range in Manassas, Va. (Dayna Smith for The Washington Post)

As Corey A. Stewart has campaigned for the Republican nomination for U.S. Senate from Virginia, he has sought help from far-right groups, complaining that his party’s establishment has tried to thwart his progress.

But that has led to embarrassing episodes in which Stewart associated with people with extreme racial views whom he later disavowed, saying he did not know about their beliefs at the time.

Most recently, Democrats and supporters of state Del. Nicholas J. “Nick” Freitas (R-Culpeper) — Stewart’s chief opponent in Tuesday’s primary — have used social media to highlight a 17-month-old video of Stewart calling Paul Nehlen, a self-professed “pro-white” candidate for Congress in Wisconsin, his “personal hero,” while praising him for challenging House Speaker Paul D. Ryan (R-Wis.).

The video was shot on Jan. 20, 2017, at the Virginia Women for Trump ball and featured Stewart and Nehlen in tuxedos, exchanging compliments. It was the night Trump was inaugurated as president and before Nehlen posted a host of inflammatory comments on Twitter.

Those posts attacked Muslims and Jews, and one showed an image of the face of “Cheddar Man,” the dark-skinned man believed to be the first modern Briton, over a picture of Meghan Markle, now England’s Duchess of Sussex.

In the wake of comments Nehlen made in December, Stephen K. Bannon, Trump’s former chief strategist, and other prominent conservatives cut ties with him. Twitter permanently suspended Nehlen’s account in February.

Stewart, the chair of Prince William County’s Board of Supervisors, said he also cut ties with Nehlen and no longer considers him a hero.

“That was before he went nuts and started spewing a bunch of stupid stuff,” Stewart said earlier this week about the video, adding that his campaign has removed any mention of Nehlen on its websites. “When he started saying all that crazy stuff, I wanted nothing to do with him after that.”

The blowback — coming in a week when the conservative America’s Liberty political action committee revealed in a federal filing that it plans to spend $225,000 on ads supporting Freitas before the election — shows the potential political price Stewart faces when flirting with the far-right fringes of his party.

It mirrors a problem Stewart had last year during his unsuccessful bid for the GOP nomination for governor. He said he regretted attending a news conference about Confederate monuments with Jason Kessler, who later organized a white-nationalist rally in Charlottesville that erupted into violence and led to the death of a 32-year-old woman.

Stewart has said the news conference also occurred before he knew what Kessler was about.

Both connections have nonetheless haunted Stewart’s recent appearances — giving fuel to his political opponents who argue he has not rejected those ties forcefully enough and is damaging the party’s image in Virginia.

“I’m getting a little tired of the Republican Party getting slammed with these sort of accusations because someone like Corey Stewart can’t figure out who he should not be associating with,” Freitas said Wednesday. “This isn’t him getting caught in a picture with somebody. This is him proactively associating himself with these people.”

In response, Stewart’s campaign accused Freitas and other Republican critics of unfairly implying Stewart is guilty by association.

“It’s sad to see establishment Republicans using leftists tactics of CNN — labeling rule-of-law conservatives racists and bigots — to advance the very same open-border, pro-amnesty agenda the left wants here in Virginia,” the campaign said.

Stephen J. Farnsworth, a political-science professor at the University of Mary Washington in Fredericksburg, said Stewart has shown great political skill in wooing conservative voters through his call to protect Confederate monuments and, recently, an appearance in Richmond, where he called Republicans “flimsy” for giving in on the fight over Medicaid expansion — while holding up a roll of toilet paper.

But should he win Tuesday, those tactics would probably backfire in a general election, Farnsworth said.

“His ability to generate headlines over such things as waving toilet paper in Richmond and the Confederate legacy movement are poison with those moderate suburban voters who decide statewide elections in Virginia,” Farnsworth said. “The strategy that wins a Republican nomination may doom a general-election candidacy.”

In addition to Freitas, Stewart is also competing with E.W. Jackson, a Chesapeake minister who is making his third bid for statewide office. All three men are Trump admirers.

But Stewart has portrayed himself as an anti-establishment candidate and the only person who can turn out Trump voters in November in a general-election race against Sen. Tim Kaine (D), who is seeking reelection to a second term.