NEW YORK — New York City’s requirement that infants and preschoolers in city-regulated child care or school-based programs must get yearly flu shots was upheld Thursday by the state’s highest court.

The Court of Appeals said that the city’s Department of Health had the authority to require the shots, a rule the city first enacted in 2013 during Mayor Michael Bloomberg’s administration.

A group of mothers filed a lawsuit in 2015, saying officials had overstepped their authority in requiring the annual vaccinations for children between the ages of 6 months and 5 years.

In its unanimous ruling, the court said the “promulgation of the flu vaccine falls squarely within the powers specifically delegated to the department.”

Health Commissioner Dr. Mary Bassett says the ruling is a “great win for New York City children.”

“Children who receive the influenza vaccine are less likely to get sick, less likely to need medical attention and less likely to die from influenza,” she said. “This decision will help us protect more than 150,000 children in City-regulated day cares and preschools across the city.”

The city said the mandate would go into effect immediately, and the more than 150,000 children in programs that are regulated by the city would be required to get the flu vaccine by December 31.

A lawyer representing the plaintiffs did not immediately comment.

The flu is a contagious respiratory illness. It’s spread by a virus, and can be unpleasant but relatively mild in many of those who get it. But it can also lead to a more severe illness and possibly death in some, with young children and the elderly at most risk.

Flu seasons can vary in severity. The Centers for Disease Control and Prevention has estimated that there have been between 12,000 and 56,000 flu-related deaths in recent flu seasons.

In New York City, five children died from the flu in the 2017-2018 flu season, officials said.

How well flu vaccines work can also vary from season to season, but health officials recommend them annually for people over the age of six months.