The recent failure of New Jersey lawmakers to pass a measure that would have ended all non-medical ­exemptions from mandatory ­immunizations at schools was a victory for anti-vaccination cranks — and a public-health disaster.

The success of vaccines led to the once-deadly scourge of measles being declared eliminated by international health authorities in 2000. But the recent revival of the disease is evidence of the influence of anti-vaxxers, who have sold scared parents a myth that vaccines cause autism.

Every leading medical authority has authoritatively debunked that claim. But the Internet conspiracy theory behind this movement continues to spread with the help of celebrities and faux experts like Robert F. Kennedy Jr. Thanks to their ability to persuade families to skip vaccinations, the Centers for Disease Control and Prevention last year recorded the highest number of measles cases in a generation.

Common sense prevailed in ­Albany last year, when the New York Legislature responded to the crisis by enacting a law that stopped parents from seeking religious exemptions to vaccinating their kids. That was necessitated by an outbreak of measles that was largely centered on ultra-Orthodox neighborhoods in Brooklyn.

While the overwhelming majority of Orthodox Jews get their children vaccinated, a small ­minority has been duped by false claims that vaccines contain non-kosher substances. Others have fallen for the same sort of misinformation that circulates among the practitioners of trendy New Age spiritualism — and has nothing to do with traditional faith.

Anti-vaxxers argue that denying parents the right to determine whether their children get vaccinated infringes on their freedom. That sounds like an affirmation of America’s heritage of constitutional liberty. But those who refuse vaccinations are doing more than endangering the health of their families. Creating a herd immunity that wipes out dangerous viruses is the only way to eliminate diseases like measles that once killed thousands every year.

Vaccinating all healthy children is also the only way to ensure the safety of those who for various reasons are too ill to be immunized. In such cases, the interests of the public in avoiding preventable suffering and death fully justify legal mandates for vaccinations.

But a lobbying blitz in New Jersey bulldozed these principles, resulting in the state Senate’s failure to pass the Assembly’s bill ending the religious waiver. It was the latest reminder of the power of a loud minority, motivated by misinformation, to thwart both the public interest and the will of the overwhelming majority of citizens.

Especially troubling was the willingness of the Orthodox group Agudath Israel to involve itself in the Garden State controversy after wisely staying out of the debate in the Empire State.

The group does a fine job standing up for the rights of Jews and other people of faith. It also explicitly ­endorses vaccination. But it came to a mistaken conclusion — namely, that government accommodation of faith should mean rabbis having a right to declare immunizations unwarranted in particular cases.

Traditional Judaism prioritizes life-saving measures. There is nothing in it that prohibits vaccines. Asserting that mandatory vaccinations violate religious liberty is especially foolish, since it undermines efforts to defend that vital principle against genuine government threats. It risks marginalizing those whose faith leads them to take unpopular stands on issues like contraception, abortion and gay marriage.

Public-health advocates need to speak up with the same urgency as those who are spreading lies about vaccines. State Senate President Stephen Sweeney has reintroduced a bill on vaccines and vowed to “go to war” for mandatory immunization. Gov. Phil Murphy and New Jersey lawmakers need to get behind Sweeney.

Those legislators who folded in the face of anti-vaxxer fervor need to understand that they have a duty to defend the state’s children against quack theories that are helping to revive diseases like measles that ought to be extinct.

Jonathan S. Tobin is editor in chief of JNS.org. Twitter: @JonathanS_Tobin