But after weeks of sustained and boisterous protests by vaccine skeptics, as well as a last-minute effort to amend the proposed bill to win the support of key lawmakers, the effort collapsed Monday in the New Jersey state Senate.

The Senate president, Stephen M. Sweeney, maintained that science, not protesters, would eventually emerge victorious.

“It’s going to get done,” Sweeney, a Democrat, said, repeating a vow he had made since last month when a far more sweeping version of the bill passed in the Assembly but failed to win enough support in the Senate. Democrats control both chambers.

“They can bang on their drums and their sirens and their truck horns,” Sweeney said over the din of protesters after it became clear that the measure was a single vote shy of passage. “This is a real public health emergency.”

The bill would have ended a policy that allows parents in New Jersey to cite religious beliefs as the reason their children have not been immunized, without affecting the child’s ability to be enrolled in school.

Doctors and public health experts had said the original bill was urgently needed to prevent the kind of measles outbreak that occurred in the region last year. They emphasized that there is an overwhelming scientific consensus that vaccines are safe and effective.

Sen. Loretta Weinberg, a Democrat and a sponsor of the legislation, said that the Senate would immediately reintroduce a new version of the bill and begin the process anew. This time, she said, the Legislature might hold public hearings with doctors and scientists to debunk opponents’ concerns.

“The science is settled on this,” Weinberg said.

In its original form, the bill would have included all students enrolled in any school or college, public or private, making it one of the most sweeping among the several states that have voted to end religious exemptions to immunization. Only medical exemptions from vaccines would have been permitted at most schools and day care centers.

But the legislation was altered last week to apply only to public schools, a change that appeared to raise new concerns, even among lawmakers who had supported the original legislation.

The private schools and day care centers that would have been exempt under the amended version of the bill would have been required to collect and share data on the number of enrolled students who had not been fully immunized.

The proposed compromise did nothing to quell the anger of the hundreds of protesters, who packed the courtyards outside the state House on Monday, as they have done regularly over the past two months. Children banged on makeshift drums as parents shouted into megaphones. One man sounded what appeared to be a shofar, the ram’s horn instrument used for Jewish religious purposes.

“Parents call the shots,” one sign read. “My God. My body. My right,” read stickers worn by many of the protesters.

After the Senate adjourned just after 6 p.m. without voting on the vaccine measure, on the final day of a two-year legislative session, the crowd outside roared.

“Thank you, God,” one group chanted.

The intensity of the prolonged protest was unlike anything in Trenton in more than a decade, many longtime lawmakers and lobbyists said.

States that have limited or revoked religion-based vaccination exemptions include California, Mississippi, Maine and New York, which was at the epicenter of a measles outbreak last year.

In New Jersey, Assemblyman Herb Conaway, a Democrat and a practicing doctor who was one of the legislation’s sponsors, defended the compromise bill in an interview before it unraveled. “We’ve had to make some concessions,” Conaway said.

“Vaccines are safe,” he added, “and we in public health need to say that repeatedly.”

Still, the amended version of the bill remained deeply unpopular with protesters who cited religious, constitutional and medical reasons for their opposition.

(BEGIN OPTIONAL TRIM.)

Sue Collins, a founder of the New Jersey Coalition for Vaccine Choice, said that it was unfair to parents who opposed vaccination and could not afford private school.

“It just made a bad bill worse,” Collins said of the amendment. “It permits the wealthy, once again, to buy themselves out of a law at the expense of the rest of us.”

Avi Schnall, the New Jersey director of Agudath Israel of America, which had lobbied against ending religious exemptions, agreed that the compromise might be worse than the original bill.

“It sets a new standard: that we are only concerned about the health and well-being of the public school children,” he said.

Later, Rabbi Schnall said he was gratified by the final outcome.

“We are relieved that the majority of the state legislators were willing to be bold enough and strong enough to stand up for religious freedom,” he said.

(END OPTIONAL TRIM.)

In New Jersey, some 94.2% of grade school students were vaccinated in the 2018-19 school year, according to state records. The rate meets the so-called herd immunity threshold that many infectious disease authorities say is required to protect the population at large.

But that percentage is down from 95.3% in 2013-14, in large part because of the rise in religious exemptions, which have grown to 2.6% from 1.7% in that time.

Dr. David Cennimo, an assistant professor of infectious diseases at Rutgers New Jersey Medical School, said any legislation that made it harder to obtain exemptions from immunization was a “good step forward,” particularly in a disease-filled world made smaller by air travel.

“We are one flight away from whatever the next thing is, especially in this area of the country,” Cennimo said in an interview.

But he said he had concerns about the differences the bill would create between public and private schools, and the potential risk that a large number of unvaccinated children could attend school together.

“You’re going to potentially cluster all these susceptible kids in the same place,” he said.

Alison Drzymkowski of Point Pleasant, who was in Trenton on Monday and last month to rally against the bill, said she was “hesitantly excited” that it had not passed.

“Not overjoyed, because it’s not gone for good,” said Drzymkowski, 31, who has two children. “But I feel really proud that I was able to assemble with people and fight for our rights, and legislators listened.”

This article originally appeared in The New York Times .