Republican U.S. Senate candidate Corey Stewart talks with Meredith Stewart Iler, left, from Cypress, Tex., and Jennifer Hammond from Arlington, Va., at the Virginia Women for Trump's "Tea for Trump" event on June 24 at Trump International Hotel in Washington. (Katherine Frey/The Washington Post)

As a Senate candidate in Virginia, Republican Corey A. Stewart promised to run “the most vicious, ruthless” campaign, a pledge he has largely kept with a steady stream of caustic social media postings aimed at his opponent, Sen. Tim Kaine (D).

But with fewer than 40 days before the Nov. 6 election — with money scarce, his poll numbers low and little support among the GOP establishment — Stewart is struggling to reboot.

Aiming to blunt his bombastic image, he is blaming the abrasive campaign he has run for more than a year on bad advice from a top consultant he recently fired.

At a debate Wednesday, Stewart presented himself as a pragmatic leader able to bridge differences to get things done in Prince William County, where he chairs the Board of County Supervisors.

But Stewart didn’t seem able to resist his caustic ways, implying without evidence during the debate that Kaine has been accused of sexual harassment.

“Who is the real Corey Stewart?” Mark Rozell, a George Mason University professor who was on the debate panel, asked Stewart.

Stewart responded with another attack on Kaine.

No matter the answer, Stewart is trying any way he can to gain ground on Kaine, who leads by nearly 20 points in most polls. After outraising Stewart $19.3 million to $1.3 million, Kaine has an advertising budget and logistics operation that have dwarfed the Republican’s bare-bones campaign.

Stewart said his firing last month of Noel Fritsch — a political consultant who also worked on his unsuccessful 2017 bid for governor — was an effort to steer his campaign away from an angry tone that alienated potential supporters as it curried favor from the extreme right, including white supremacists such as Paul Nehlen.

Since then, Stewart has woven into his speeches sober topics such as the gross domestic product and unemployment rates.

At a Richmond forum before a predominantly black audience, Stewart didn’t mention his previouspledges to preserve Confederate monuments, his past associations with white nationalists or his decision to attack the Rev. Al Sharpton last month as a “race hustler.”

The audience had warmly greeted Kaine just an hour before.

Stewart told the group that his staff questioned his decision to attend. “My advisers were like, ‘Never go into a forum unless it’s a friendly forum, unless you’re absolutely certain people are going to be with you,’ ” he said. “And I think that that’s the problem in America. I think it’s the problem in Washington. I think that we have two sides that aren’t talking to one another.”

Earlier in the week, Stewart appeared before environmentalists at a Fairfax County forum that also featured Kaine.

The audience nodded in agreement as Kaine argued for cultivating green energy jobs and making it harder to win federal approval for oil and natural gas pipelines.

Stewart, who has called the idea of man-made climate change “a hoax” and told the audience that he didn’t believe humans caused global warming, prefaced his remarks with an appeal for more bipartisan discussion.

“So far, we’re just yelling,” he said of national politics.

Then he said that flooding in Virginia’s coastal communities is a function of sinking land — not rising sea levels — an assertion that prompted sarcastic laughs from the crowd.

Still, Eric Seibold, 44, was impressed that Stewart even showed up.

“To come into a lion’s den like this?” he said. “I’ve got to give him at least a little respect.”

Yet even as he tries to moderate his message, Stewart repeatedly drifts toward the inflammatory approach that helped him win his party’s nomination in June, warning about the menace of Latino gangs or ridiculing the allegations of sexual misconduct facing Supreme Court nominee Brett M. Kavanaugh as “a bunch of crap.”

Stewart fired Fritsch, whom he has paid $52,000 since early 2017, after the consultant tweeted, under Stewart’s name, that a Michigan Democrat who is Muslim is an “ISIS commie.” Stewart’s constituents in Prince William County include a large Muslim population.

“I was having people come up to me saying: ‘Your tweets and Facebook posts are angry,’ ” Stewart said. “I didn’t like what the campaign looked like, and it was in my name. And so we made that change and so you’re seeing the real guy now.”

He said Fritsch also encouraged him to forge a relationship with Nehlen, the onetime Wisconsin congressional candidate whom Stewart praised as “one of my personal heroes” in a video made in January 2017, before Nehlen’s anti-Semitic views made him an outcast within the Republican Party.

Fritsch, who briefly worked for Nehlen, was “out of touch with my voice,” Stewart said.

But Fritsch, in a telephone interview, characterized Stewart’s campaign as “dysfunctional” and called Stewart “erratic.”

“He’s untethered from the claims he had to being a hard-line conservative and warrior for freedom of speech,” Fritsch said, accusing Stewart of being lax with fundraising. “He’s moderating.”

With time running out, Stewart is caught between the need to appeal to moderate voters while remaining provocative enough to capture free media attention that helps him reach potential supporters he doesn’t have funds to court otherwise, political analysts say.

Stewart’s dilemma is shared by Republicans in swing districts and states across the country as they navigate a polarized electorate in midterm elections where President Trump’s unpopularity could give Democrats control of at least the House, analysts say.

“Trying to define yourself, much less redefine yourself, is a real challenge when President Trump dominates the news cycle virtually every minute of every day,” said Stephen J. Farnsworth, a political-science professor at the University of Mary Washington in Fredericksburg.

For Stewart, that problem is particularly acute, Farnsworth said.

Stewart rose to prominence last year when he almost won the GOP nod for governor by championing Confederate monuments, railing against illegal immigrants, raffling off an AR-15 semiautomatic rifle and attacking moderate Republicans for failing to fully back Trump. In the Senate race, he has shown unyielding support for Trump, boasting that his hard-line approach to illegal immigration in Prince William made him “Trump before Trump was Trump.”

“If Corey Stewart had presented himself as a more conventional Republican when he first entered statewide politics, he probably wouldn’t have been noticed in the way he has as a more aggressive figure,” Farnsworth said. “But getting known doesn’t mean getting elected statewide. Those are two very different things.”

Stewart said the image he now wants to cast — “conservative, strong and stern” — can appeal to more moderate voters.

At times, that has meant avoiding the kinds of controversies he once sought.

This month, Stewart backed out of speaking at a Washington rally to support Trump after learning that several other scheduled speakers harbored white nationalist views. One — YouTuber Vincent James Foxx — has argued that the Trump administration should not hire African Americans.

“During the primary and the gubernatorial primary, we weren’t as careful as we should have been with regard to the people who we were associating with,” Stewart said. “I’m going to take responsibility for everything that happens in my campaign. The buck stops here. But it really angered me because I was getting in trouble for stuff that members of my campaign were doing.”

It is hard for voters to know which Corey Stewart is authentic and which is manufactured, said Quentin Kidd, director of Christopher Newport University’s Wason Center for Public Policy.

Although he fired Fritsch, Stewart has not severed ties with Rick Shaftan, another adviser, who in his social media posts has used a profanity to describe majority-black cities while bemoaning that the South lost the Civil War.

“It doesn’t say anything that voters should feel comfortable with,” Kidd said. “I don’t know how a moderated Corey Stewart would make amends for all of the things that the Corey Stewart that you and I know has said and done.”