It is not clear when exactly the attendees who later tested positive were infected, and the White House has said all guests tested negative for the virus before the event. Still, it can take several days after exposure for the virus to be detected by a test.

The indoor White House gathering was far from the only time this week that Mr. Trump was in close quarters indoors with family, aides or supporters.

Ahead of the first presidential debate on Tuesday night in Cleveland, Mr. Trump held closed-door preparation sessions on Saturday, Sunday, Monday and Tuesday with a half-dozen aides and advisers, including Bill Stepien, his campaign manager; Kellyanne Conway, a former White House adviser; and Chris Christie, the former governor of New Jersey. All of them have since tested positive for the virus. Rudolph W. Giuliani, the president’s personal lawyer, also participated in debate preparation sessions but has said he tested negative.