Virginia Republican John Gray figured he was being smart. He paid $30 to delete some offensive and inflammatory tweets as part of his bid to become chairman of the Prince William Board of County Supervisors.

But after Gray’s campaign disclosed two $15 payments to a service that scrubbed his Twitter account, the line-item entry attracted attention from his chief opponent, Democrat Ann Wheeler, whose team easily dug up the deleted posts and shared them with The Washington Post.

The thousands of tweets reflected Gray’s often-confrontational and incendiary worldview. Some used stereotypes to mock violence and political protest in African American communities, exhibit religious intolerance against non-Christians and denigrate people with opposing political opinions.

Now, as Gray seeks the highest office in the rapidly diversifying county of 456,000 people, he finds himself doing exactly what he had hoped to avoid:

Explaining why, in 2016, he tweeted the falsehood that Islam sanctions domestic abuse; why he wrote “a funny tweet” that same year that said African Americans would stop “rioting” and take a knee if someone played the national anthem; and why, in 2017, he called former New Mexico governor Gary Johnson “a moron” for wishing Indians a happy Diwali.

Wheeler, who is vying with Gray to fill the seat being vacated by longtime board chairman and Republican firebrand Corey A. Stewart (At Large), said the attempts to hide the posts show Gray is unfit to lead Virginia’s second-largest jurisdiction.

“I don’t hide who I am,” Wheeler said Monday. “The bottom line is, he deleted those tweets because he believed they’re too extreme for Twitter. If they’re too extreme for Twitter, they’re too extreme for Prince William County, and he has no business running Prince William County.”

Gray owned up to some of the tweets, adding that a few of the more offensive ones — including crude comments about Hillary Clinton — were posted to his Twitter account by a campaign consultant whom he has since fired.

“I agree that some of them were completely inappropriate,” Gray said, adding that he decided to delete the tweets to avoid giving his opponents something to ­criticize.

“I’ll be sure to call my campaign consultant and ask: ‘Can you refund my $30?’ ” he said in jest. “Obviously, it didn’t work.”

Political candidates have occasionally stumbled into controversy over what they’ve posted on social media, including President Trump. Last year, when Stewart was trying to unseat Sen. Tim Kaine (D-Va.), his campaign posted a statement on Twitter calling a Muslim candidate for governor in Michigan “an ISIS commie.” Stewart had that post deleted and blamed it on a consultant he also fired.

Gray admits to not having much of a social media filter before he announced his candidacy in March — and even in the months that followed.

In July, he posted a suggestion that Muslim hookah-bar owners should be forced to sell alcohol, even though doing so would be against their religion. Gray later said he regretted that tweet, which was intended as a reference to a legal battle involving a Colorado baker who refused to make a wedding cake for a same-sex couple based on his religious beliefs.

His campaign launched the cleanup effort about the same time he posted that tweet.

Gray was less apologetic about some of the other deleted tweets, including one in 2017 that said the “bong and dildo holders” who tried to impeach Trump would be met with “300 million weapons and an estimated 2 billion rounds of ammo” in the conservative uprising that would be sure to follow.

“It’s not inciting violence,” Gray said Monday, explaining that the tweet was in reply to somebody else’s tweeted prediction of an uprising.

He also defended a 2016 tweet about Muslim men and domestic abuse, posted in reply to a Washington Post article that included an account of domestic abuse suffered by the wife of Omar Mateen, the gunman who killed 49 people at a gay bar in Orlando in 2016.

“Well, what did you expect? Being Islamic you knew he had the right to beat you,” Gray posted. Gray said the comment was based on his understanding of Sharia law.

Rafi Ahmed, president of the Dar Alnoor Islamic Community Center in Prince William, said Gray may have been referring to a common mischaracterization of a section in the Koran about domestic relations, which, Ahmed said, sanctions light forms of spousal discipline but nothing physical.

“Striking is not an option,” Ahmed said. “If Mr. Gray has that perception, I would be more than willing to sit down with him and talk on this subject in detail.”

Donald Scoggins, an independent also running for the chairman’s seat, said Gray’s tweets are inexcusable: “Such an individual does not deserve to be an elected official in Prince William County.”

Muneer Baig, another independent seeking the office, said he did not want to criticize Gray. “I prefer to focus on what’s good,” he said. “We’ve all got skeletons in our closet.”

Gray said he plans to cut down on social media. “Twitter: I used to love it,” he said. “I barely look at it now.”