SANTIAGO, Chile (AP) — Chilean lawmakers took a major step toward legalizing abortion in some cases on Wednesday, a dramatic development in one of Latin America's most traditionally conservative countries.

In a marathon session lasting well past midnight, the Senate voted to allow abortions when a mother's life is in danger, when the fetus is not viable and in cases of rape.

A version of the bill was approved in 2016 by the lower house, where a vote on changes introduced by the Senate was postponed to Thursday. President Michelle Bachelet supports the measure and has said she would sign the law.

But opposition lawmakers from the conservative political bloc Chile Vamos said they would appeal it to Chile's Constitutional Tribunal, which could rule it unconstitutional.

Chile is one of just four countries that currently prohibit abortion in all cases, according to the New York-based Center for Reproductive Rights. A handful of others have rules so restrictive that they amount to de facto bans.

But views have been shifting in Chile on a number of social issues that were once taboo.

The predominantly Roman Catholic nation began to allow divorce only in 2004, and in 2015, Congress recognized civil unions for same-sex couples. Recently it became the first country in Latin America to allow cannabis-based medicines at pharmacies.

The changing attitudes mark a generational shift as younger people born after the 1973-1990 military dictatorship of Augusto Pinochet come of age.

The trend has been more evident since a wave of student protests demanding education reform began in 2011 and has accelerated as a string of priest sex-abuse scandals prompted many Chileans to question Catholic doctrine.

Currently women who get abortions in Chile are subject to up to five years in jail, as are doctors or medical personnel who assist with the procedure. A woman who arrives at a hospital with signs that she has had an abortion is supposed to be reported to the police, or the hospital faces sanction.

"I am not in favor of abortion, but I think we are talking about three exceptional cases," said lawmaker Carolina Goic, who heads the center-left Christian Democratic Party. "The State's answer cannot be simply sending women to jail."