A Virginia man threatened to kill a Republican congressman while saying he was trying to defend special counsel Bob Mueller’s probe into the Trump administration, prosecutors said Friday in announcing federal charges against the man.

Christopher Michael McGowan was afraid that Mr. Mueller’s probe might be derailed and took exception to a local congressman, Rep. Bob Goodlatte, who had raised questions last year about the fairness of the special counsel investigation.

In a series of Twitter messages dating back to December Mr. McGowan said he was defending Mr. Mueller, and repeatedly vowed to obtain a gun to kill Mr. Goodlatte.

After some December messages local police visited him and he said didn’t actually intend to hurt the congressman. But in April he renewed the threats: “You keep [expletive] with our constitution and challenging Mueller and the last you see will be my patriot ass behind a gun you should have long ago prevented me owning pulling a trigger to your head (sic.),” Mr. McGowan wrote in an April 1 message.

Minutes later he posted another message bragging about the threat, acknowledging he had publicly threatened a sitting congressman and predicted he would not be punished. “You better get on those gun laws. I am buying one intended for you in 3 days. Can you legally stop me?” he then posted.

Soon after that he sent an email to local police saying he’d been drinking and didn’t mean what he said.

But just days later he was back on Twitter again bragging about killing Mr. Goodlatte.

Mr. Mueller has become something of a hero to anti-Trump voters during his probe into interactions between the Trump campaign and Russian operatives. He has secured charges and, in some cases, guilty pleas from Trump campaign figures for lying to the FBI and hiding money. He has also secured charges against Russians the government says interfered in the election.

But he has not at this point personally connected Mr. Trump to any wrongdoing, and the White House has vehemently denied Democrats’ charges of collusion.

Mr. Mueller’s hiring of employees with ties to Democrats sparked questions of bias in the probe last year, and Mr. Goodlatte — who is chairman of the House Judiciary Committee — raised the issue at an oversight hearing in December, about the time the government documents some of Mr. McGowan’s first threatening tweets.

Mr. McGowan, 38, is charged with making a threatening communication through interstate commerce.

“Federal law criminalizes threatening communications made through the internet or a telephone, and these types of threats are not protected by the First Amendment,” said Thomas T. Cullen, U.S. Attorney for the Western District of Virginia.