BUENOS AIRES (Reuters) - Argentine senators rejected a bill to legalize abortion after an impassioned debate ran into the early hours of Thursday, pushing back against a groundswell of support from a surging abortion rights movement.

The Senate voted 38 to 31 against the proposed measure, which would have legalized a woman’s right to seek an abortion into the 14th week of pregnancy. The bill had narrowly passed in the lower house in July.

Families and clergy in baby-blue bandanas gathered outside the congressional palace as the result came in just before 3 a.m., waving Argentine flags in support of the Catholic Church’s anti-abortion stance in Pope Francis’ home country.

“What this vote showed is that Argentina is still a country that represents family values,” anti-abortion activist Victoria Osuna, 32, told Reuters.

Current Argentine law only permits abortions in cases of rape, or if the mother’s health is at risk.

Abortion rights supporters, clad in green bandanas that have become a symbol of the movement, danced to drum lines and swarmed the city’s streets to the end, despite a biting wind and cold rain.

Many had camped in front of Argentina’s National Congress since Wednesday night.

Slideshow ( 21 images )

“I’m still optimistic. It didn’t pass today, but it will pass tomorrow, it will pass the next day,” said abortion rights supporter Natalia Carol, 23. “This is not over.”

Uruguay and Cuba are the only Latin American countries that now have broadly legalized abortion.

In Brazil, the Supreme Court is set to consider whether current law, which allows terminating pregnancies only in cases of rape, fetal deformation or when the mother’s life is in danger, is unconstitutional.

But passing a pro-abortion law will face hurdles in Brazil’s increasingly conservative Congress, with a growing Evangelical Christian caucus that is staunchly opposed.

Women’s rights advocates, however, hope that a more liberal judiciary in Brazil will at least decriminalize abortion to help avoid deaths from botched terminations in a country where hundreds of thousands of women resort to clandestine clinics each year.

Ahead of the Senate vote in Argentina, President Mauricio Macri called the debate “a win for democracy.” Macri said he was personally against abortion, but would sign the bill if it passed.

Slideshow ( 21 images )

Argentina’s abortion rights movement, backed by feminist groups galvanized in recent years to stop violence against women, argued that the bill would end unregulated abortions that government data show as the leading cause of maternal deaths.

There are at least 350,000 illegal abortions in Argentina every year, the Ministry of Health estimates, though international human rights groups say the number may be higher.

The move to legalize abortion in Argentina is a “public health and human rights imperative,” said New York-based Human Rights Watch.

“Just because the bill got shot down, it will not stop the movement,” said Paula Avila-Guillen, a director of Women’s Equality Center, an abortion rights advocacy group. “We will be there at the next legislative opportunity.”