The rivers that run into New York Harbor will be unfit for recreational activities at least through Sunday because of a catastrophic fire that shut down one of the city’s largest sewage treatment plants, the city’s health department said Thursday.

The declaration, rare in scope, was made as millions of gallons of untreated sewage were being discharged from Manhattan into the Hudson and Harlem Rivers.

As New Yorkers reeled from hot weather, the authorities also advised against swimming at four city beaches on Staten Island and in Brooklyn. The remaining public beaches were still safe to use, but officials worried that a tide of sewage might force more restrictions or closings unless at least part of the crippled treatment plant could be brought back on line before Friday night.

The prospects for a quick recovery from the fire this week, which started in the main engine room of the North River Wastewater Treatment Plant in Harlem, were uncertain.