For weeks, Rep. Louie Goh­mert (R-Tex.) has defied expert advice on how to thwart the spread of the coronavirus.

He was seen walking the halls of the Capitol without wearing a mask. He often didn’t social distance.

Then on Wednesday came the bad news: Gohmert, tested by the White House in advance of a planned Air Force One flight with President Trump, learned that he had become infected.

But even as the conservative congressman vowed to avoid spreading it to others, he continued to ignore expert advice. He insisted on returning to the Capitol. And he used his platform to spread false information about the virus, saying that those who test positive later become immune and suggesting that face masks make it more, not less, likely that one will become infected.

“It is interesting, and I don’t know about everybody, but when I have a mask on, I’m moving it to make it comfortable, and I can’t help but wonder if that puts some germs in the mask,” Gohmert said in a video that he appeared to film from his office.

He added: “Keep your hands off your mask. But anyway, who knows. But now that I apparently have it, I will be very, very careful to make sure I don’t give it to anybody else, and we’ll see how it goes.”

By the end of the day Wednesday, Gohmert had emerged as a national model for exactly how experts say people should not behave during a pandemic. He was blasted by Democrats as a pariah who should leave the complex, where he sleeps at night in his office, to avoid further spread. And he was the inspiration for a new rule imposed by House Speaker Nancy Pelosi (D-Calif.) to require members to wear masks on the House floor.

“Louie Gohmert lives and sleeps in his Capitol Hill office,” Rep. Gerald E. Connolly (D-Va.) said in a tweet. “Now that he’s tested positive, he cannot be allowed to quarantine there. He’s put Members and staff at enough risk already. I wish you well, @replouiegohmert. But you need to figure out a better option.”

The news of Gohmert’s diagnosis reverberated on Capitol Hill, raising fresh questions about testing of lawmakers and protocols amid the coronavirus pandemic, and prompted the Justice Department to announce that Attorney General William P. Barr would be tested.

Late Wednesday, the Justice Department said Barr tested negative.

Gohmert, who has frequently walked around the Capitol without wearing a face mask or maintaining social distance from others, was in proximity to the attorney general on Tuesday before a congressional hearing at the Capitol — and both were maskless.

Pelosi announced that she was implementing a new order that will require all lawmakers to wear a mask while appearing on the chamber floor and is also considering other measures to more strictly enforce the wearing of masks across the Capitol complex.

In the spring, Pelosi and Senate Majority Leader Mitch McConnell (R-Ky.) rejected an offer from the Trump administration to get the sort of tests that are now routine at the White House, but Gohmert’s diagnosis prompted senior lawmakers to reconsider their opposition on mandatory testing for members of Congress.

White House Chief of Staff Mark Meadows said the Trump administration is standing by to help should leaders on Capitol Hill agree on a plan.

News of Gohmert’s diagnosis was first reported by Politico.

Gohmert has made dubious claims about the novel coronavirus, mask-wearing and testing as Trump has worn a mask on just a few occasions and some other Republicans have been resistant to the practice, which has become highly politicized.

In May, at a White House event with Trump, Gohmert said, “We had tests and nobody in here has the coronavirus unless it’s somebody in the media. So the only reason we would wear masks is if we were trying to protect ourselves from you, in the media. And we’re not scared of you.”

Gohmert has urged the Food and Drug Administration to approve hydroxychloroquine, the anti-malaria drug that Trump has promoted as a treatment for covid-19 that doctors have said is ineffective against the virus. In April, Gohmert also said that German hospitals were using a disinfectant powder in mist form to kill the virus for up to 14 days — a claim widely debunked by German health officials who said no such product was being used.

Gohmert said he was in contact with Sen. Rand Paul (R-Ky.), one of the first of dozens of lawmakers to test positive for the virus.

“Rand Paul was just texting me that the good news is that in 10 days or so, I should be fairly well immune,” Gohmert declared.

Public health experts remain uncertain about whether recovered covid-19 patients are actually immune to the disease, however, and there are reports of some patients testing positive months after they were first diagnosed. Even after his return to the Senate, Paul, an ophthalmologist, refused to wear a face mask, telling reporters, “I have immunity.”

It was not immediately clear in what location Gohmert was planning to self-isolate. His office did not respond to repeated requests for comment. Gohmert is among the dozens of House members who sleep in their offices, according to the Capitol Hill newspaper Roll Call, and some of his colleagues voiced concern Wednesday that the lawmaker may continue to do so even after contracting the coronavirus.

“Louie Gohmert lives and sleeps in his Capitol Hill office,” Rep. Gerald E. Connolly (D-Va.) said in a tweet. “Now that he’s tested positive, he cannot be allowed to quarantine there. He’s put Members and staff at enough risk already. I wish you well, @replouiegohmert. But you need to figure out a better option.”

In the wake of Gohmert’s announcement, Rep. Kay Granger (R-Tex.) announced that she is self-quarantining “out of an abundance of caution” because of recent close contact with the congressman. Granger was seated next to Gohmert on a flight from Texas to Washington on Sunday night, Sarah Flaim, a spokeswoman for the 77-year-old Granger, said in a statement.

Because of the memorial services for the late congressman John Lewis (D-Ga.), the full House has held only one roll call vote, at lunchtime Monday, over the past five days, so many lawmakers would not have been around the Texan in recent days.

Gohmert has typically worn a mask as required during House hearings, including during Tuesday’s nearly six-hour testimony by Barr before the House Judiciary Committee.

That session was held in a massive auditorium with lawmakers spaced out, and Gohmert appears to have adhered to the committee rules that one must wear a mask at all times unless it is his or her turn to speak.

Soon after news of Gohmert’s diagnosis, House Majority Leader Steny H. Hoyer (D-Md.) blasted Gohmert and other Republicans who have declined to wear a mask for “showing no personal responsibility or consideration for others.”

Hoyer said Gohmert’s positive test should restart consideration for a mandatory testing program for all lawmakers, dozens of whom have been traveling back and forth this summer to states that are considered coronavirus hot spots such as Texas.

“This is a moment where we ought to discuss it again,” Hoyer told reporters on a conference call, suggesting that he would discuss the matter with Pelosi and GOP leaders.

Sen. Roy Blunt (R-Mo.), chairman of the Senate Rules and Administration Committee, told reporters Wednesday that he has renewed his push to require regular coronavirus testing for members of Congress who travel, as well as testing for staffers “every couple of weeks or a month.”

Ultimately, Blunt said, any proposal will need to garner the support of McConnell and the Capitol physician.

“I think, particularly for members of Congress who are going back and forth, they represent sort of the perfect Petri dish for how you spread a disease — you know, send 535 people out to … 535 different locations on about 1,000 different airplanes and bring them back and see what happens,” Blunt said. “It seems to me there’s a better path forward.”

Meadows, too, said Wednesday that he thinks it would be “prudent” for congressional leaders to agree to institute testing for members of Congress.

In a brief exchange with reporters, House Minority Leader Kevin McCarthy (R-Calif.) confirmed that he and Meadows discussed testing. He also blamed Pelosi for previously rejecting the Trump administration’s offer to supply Capitol Hill with rapid coronavirus tests, even though McConnell joined the speaker in writing a joint letter in May declining the proposal.

“Testing would be critical, because people can be here and have it and you would not know,” said McCarthy, who referred to Gohmert as “Congressman Covid” before quickly correcting himself.

McConnell’s office declined to comment Wednesday on testing members of Congress. The two leaders have indicated that health professionals and others should get priority in testing.

In Wednesday’s video, Gohmert pushed back against the notion that he has been lax in wearing face coverings while on Capitol Hill.

“Look, I’ve worn a mask more the last week or two than I have in the whole last four months. And I was wearing my mask at the Judiciary hearing,” he said, adding that “a couple of the other guys weren’t wearing the mask.”

The blowback from the Goh­mert situation didn’t seem to faze some Republicans, who continued to bemoan the safety precautions in the House.

During a House vote after the news of Gohmert, Rep. Jeff Duncan (R-S.C.) walked off the House floor and complained about a possible new precaution: closing the chamber between roll call votes to wipe down and sanitize the seats. Lawmakers have been spacing out their votes to ensure social distancing, which means votes take much longer than usual. Cleaning everything in between, Duncan argued, would only further slow things down.

“This is crazy!” he said, predicting that zero members of Congress have caught the coronavirus on the floor. “How much is this costing the taxpayers?”

His colleague tried to politely remind him about Gohmert.

Rachael Bade, Meagan Flynn, Erica Werner and Matt Zapotosky contributed to this report.