ALBANY, N.Y. – After a day of contentious debate, New York lawmakers voted Thursday to end the state's religious exemption from vaccines that had allowed parents to send their unvaccinated children to school or day care

The Senate and Assembly votes capped months of tense protests and negotiations amid a measles outbreak in Rockland County and New York City, which since September have seen a combined 854 confirmed cases of the disease that was once declared eliminated 19 years ago.

Nationally, cases exceeded 1,000 this year – the highest in 27 years, the Centers for Disease Control and Prevention said Tuesday.

Gov. Andrew Cuomo signed the bill into law calling vaccines "safe and effective" and the science behind them "crystal clear." It took effect as soon as he signed it.

'I am not against vaccinations':Jessica Biel says after lobbying with anti-vaxxer Robert F. Kennedy Jr.

Measles on the rise:Measles cases surpass 1,000 in span of 6 months; medical experts worry about summer travel

"This administration has taken aggressive action to contain the measles outbreak, but given its scale, additional steps are needed to end this public health crisis," Cuomo said in a statement.

Senate Majority Leader Andrea Stewart-Cousins, D-Yonkers, said the measure was necessary to improve the public health.

"We are in the midst of a measles epidemic which is completely preventable given proper immunizations,” Senate Majority Leader Andrea Stewart-Cousins said in a statement.

Protests over the bill continued Thursday, when dozens of anti-vaccination protesters and religious-rights advocates — many of them with infants or young children — crowded the Capitol, unsuccessfully urged lawmakers to vote the bill down.

The Assembly narrowly voted for the measure, 77-53, just one vote more than needed than necessary. Rarely does a bill in Albany pass with so few votes.

After the Assembly vote, opponents cursed and screamed at lawmakers from the public gallery overlooking the ornate chambers before they were removed by security. Some left in tears.

The Senate vote was 36-26.

Vote ends weeks of uncertainty

The bill, which a Siena College poll this week showed was supported by 84 percent of voters, would make New York the fifth state without a religious or philosophical exemption from vaccines required to attend school.

Maine last month also ended its religious exemption.

In the 2017-18 school year, about 26,000 students were exempt from vaccinations based on religious beliefs in New York, according to the state Department of Health. That's about 1% of schoolchildren.

The law would offer a grace period until June 30, 2020, for children to attend school if they can show they have "has received at least the first dose in each immunization series" before then.

An exemption for legitimate medical issues remains.

For weeks, the bill's passage had appeared uncertain as anti-vaccination activists lobbied lawmakers to leave the exemption in place, arguing that rescinding it would infringe on their rights to religious expression.

That was true even a few hours before the Assembly voted on the measure, when a freshman lawmaker saved it with a dramatic change of heart.

Dramatic vote Thursday

The Assembly Health Committee had to approve the measure in order for it to get a full vote.

But after a lengthy, contentious meeting Thursday afternoon in a conference room filled with vaccination skeptics and religious-rights advocates, the 26 members of the committee were deadlocked, 13-13.

Enter Assemblyman Nader Sayegh, a Democrat from Yonkers.

As Assembly staffers tallied votes and realized they were one short, Sayegh rose from his seat and approached Speaker Carl Heastie, D-Bronx, and Assembly Health Committee Chair Richard Gottfried, D-Manhattan.

Sayegh, who originally voted against the measure, decided to change his vote, giving the measure just enough votes to advance to the next committee.

Even still, Sayegh said he would vote against the bill when it comes to the Assembly for a vote.

Sayegh said the measure is "an important bill and an important issue."

"As an educator, parental choice is very important to me," Sayegh said during the vote.

"And although I will go on record as saying I would vote no on the floor on this bill, but I really feel the public and the Assembly at large deserve an opportunity to vote on this matter so I'd like to vote in favor to allow this to go to the floor."

As Sayegh announced his new vote, vaccination protester Stephanie Mahairas weeped.

"Please!" Mahairas said. "Please!"

Are vaccines safe? What you need to know about mercury, aluminum and other 'toxins'

Measles 2019:3 charts show vaccines' triumph over preventable diseases for 5 decades

Opponents vow lawsuit

As Assembly members left the committee meeting, they were met by dozens of sign-wielding vaccination opponents chanting: "Change your vote! Change your vote!"

Later, Mahairas said the vaccination bill will likely face a legal challenge. She believes it violates federal law and her First Amendment rights.

"We are religious people who believe sincerely in our religion and this that was voted on today is a violation of the Constitution and the Civil Rights Act," said Mahairas, whose father founded the Manhattan Bible Church.

Brain swelling, deafness and death:What can happen if you contract measles

Unvaccinated teen gets chickenpox:Unvaccinated teen banned from school during chickenpox outbreak now has the illness

Later in the day, lawmakers hotly debated the bill on the Assembly floor, jousting over whether ending the exemption goes too far and infringes on the rights of parents.

Assemblyman Andrew Raia, R-Suffolk County, warned that parents may be forced to get their children the vaccines even if they suffer from adverse effects from them.

"I can’t imagine being a parent put in that position where that next shot could potentially further damage your child or potentially kill your child all because the general rule of thought is everyone’s got to get vaccinated," he said.

The bill's sponsor, Assemblyman Jeffrey Dinowitz, D-Manhattan, said the law would still allow for medical exemptions from the vaccines, saying ending the exemption is important for public health.

Dinowitz sponsored the bill alongside Sen. Brad Hoylman, D-Manhattan.

"It’s been picking up more and more support and more and more of my colleagues are recognizing how important this is," Dinowitz said before the vote.

"This is about protecting children."

In the Senate, Hoylman said even a small number of students in schools who are unvaccinated poses a threat to the public's health, both in school and in the community.

He pointed that the risk is especially high among infants not yet vaccinated, as well as pregnant women and the sick. He said the cases of vaccine-preventable illnesses fell in California after it ended its religious exemption.

"We don’t want to give credence to the anti-vaxxers," he said on the Senate floor, charging that opponents can use the religious exemption as a "guise" for their misguided personal views.

New York state of emergency:Measles outbreak 'continues to rage' in New York county as state of emergency renews

New York measles 2019:Parents sue New York City Department of Health to halt vaccine mandate

Vaccine bill spurs major debate

Ending the exemption should not trump religious freedom afforded in the Bill of Rights, contended Assemblyman Michael Montesano, R-Nassau County.

"This bill is targeting the religious exemption," he said on the Assembly floor. "It’s an attack on people’s First Amendment right, their right to express their religious beliefs."

But Assemblyman Kenneth Zebrowski, a Democrat from Rockland County where measles has spread, urged his colleagues to support the bill, saying without the change, measles could spread to people in their districts.

Of Rockland's 266 confirmed measles cases, many of them have been in Orthodox Jewish communities.

"We may turn around in two months, we may turn around in six months, we may turn around in 18 months because we have a full blown epidemic: Thousands of children, maybe in your district," Zebrowski warned.

"Let’s prevent that, because that’s what we are supposed to do."

Do 'the right thing':People who can't get vaccinated during a measles outbreak rely on the healthy

Split vote in Hudson Valley

Hudson Valley lawmakers were split on the measure.

Assemblyman Thomas Abinanti, D-Mount Pleasant, Westchester County, was among the most vocal opponents, arguing that the religious exemption is rarely used and rescinding it would trample religious rights.

New York's vaccination rate is regularly around 92 percent.

“Just because you’re unvaccinated doesn’t mean you’re contagious,” Abinanti said during the Health Committee vote. "We’re targeting something that has nothing to do with the problem we’re trying to solve."

Assemblwoman Ellen Jaffee, D-Suffern, Rockland County, supported the measure. She and Abinanti were seen having a spirited discussion following the committee vote.

"What has been proven is that when a child is vaccinated, they are protected from an illness that could impact them forever," Jaffee said on the Assembly floor. "And then it could impact others. Just think of the infants that are nearby."

Along with the vaccination bill, the Senate also approved a measure to launch a statewide awareness campaign about the measles and how they are spread.

"We have to do everything we can to make sure the measles are eradicated once again," said Sen. David Carlucci, D-Clarkstown, Rockland County, the bill's sponsor. "We need to do everything."

Follow Jon Campbell and Joseph Spector on Twitter: @JonCampbellGAN and @GannettAlbany