A judge dismissed a lawsuit Thursday that challenged an emergency declaration in New York City requiring residents of certain neighborhoods affected by a measles outbreak to receive mandatory vaccinations.

Mayor Bill de Blasio issued the order last week that would require unvaccinated people living in four ZIP codes in Williamsburg, Brooklyn, to receive the measles vaccine in response to one of the largest outbreaks in decades. The outbreak has infected 329 people so far, most of them children from Orthodox Jewish communities in Brooklyn.

“This is the epicenter of a measles outbreak that is very, very troubling and must be dealt with immediately,” de Blasio said.

The outbreak started when an unvaccinated child acquired measles on a visit to Israel, where a large outbreak of the disease is occurring, according to the city health department’s website.

"Since then, there have been additional people from Brooklyn and Queens who were unvaccinated and acquired measles while in Israel," the health department said.

Unless residents within the ZIP codes can demonstrate immunity to measles, they must get the measles-mumps-rubella vaccine or face a $1,000 fine.

A group of anonymous Brooklyn parents filed an injunction for relief against the declaration, arguing the order was unconstitutional and quarantine would be an equitable solution instead.

But a judge dismissed their suit on Thursday, saying the families failed to provide an affidavit from a religious official to prove religious objections. Parents also failed to prove the declaration would compel forced vaccination, Judge Lawrence Knipel said in the opinion.

"A fireman need not obtain the informed consent of the owner before extinguishing a house fire," Knipel wrote in his ruling. "Vaccination is known to extinguish the fire of contagion."