A 2013 measles outbreak that hit two Brooklyn neighborhoods — infecting 58 people, all of them unvaccinated against the disease — cost the city’s health department nearly $400,000, according to a new study.

Between travel, testing equipment and over 10,000 hours of work by 87 staff members, the Department of Health and Mental Hygiene was forced to spend $394,448 fighting the contagion, the Journal of the American Medical Association inquiry found.

The outbreak began in March 2013, when a single infected child returned to New York from a trip to London, wrote Dr. Jennifer B. Rosen of the city Health Department, who authored the study along with two others.

From that point until June 2013, 58 people contracted measles in Williamsburg and Borough Park, ranging in age from infancy to 32 years old.

Each of the patients was a member of the neighborhoods’ Orthodox Jewish enclaves — and unvaccinated against measles, despite 46 of them being old enough to receive the inoculation, the study found.

The study credited the “insular nature of the affected community” with preventing the outbreak — the largest to hit the five boroughs since 1992 — from growing even more widespread.

Still, the authors pegged the $400,000 bill on the lack of vaccinations.

“Measles vaccine refusals or delays can lead to large outbreaks following measles importations, with costly and resource intensive response and containment,” wrote Rosen.

“The significant burden and consequences of measles outbreaks as well as other public health emergencies underscore the importance of continued support for a robust and flexible public health infrastructure for health departments.”