(CNN) Argentina's Senate voted against legalizing elective abortion in the early hours of Thursday morning, dashing the hopes of abortion rights advocates in the predominantly Catholic country, homeland of Pope Francis.

The Senate rejected the proposed bill 38 to 31, with two abstentions and one absentee.

The bill, which fueled contentious debate, would have expanded abortion rights to allow women to end a pregnancy in the first 14 weeks. Current laws allow the procedure only in cases of rape or when the mother's health is at risk.

A heavy police presence around the National Congress in Buenos Aires quickly quelled scattered confrontations after the vote's outcome was announced. As soon as the vote was announced, fireworks went off outside Congress as jubilant anti-abortion demonstrators dressed in blue -- the color of the "save both lives" movement -- danced and cheered.

Abortion rights activists gather around a bonfire to keep warm as celebratory fireworks go off in the distance.

Hundreds of thousands of people had gathered outside Congress throughout the day to mark their support for and opposition to the bill that has divided Argentine society.

A small number of pro-abortion rights protestors lit fires and threw rocks and bottles at police, who responded with tear gas and water cannon. Most of the clashes quickly died down. As many as eight people were detained, according to media reports.

Around an hour after the vote most people had left the streets around Congress, leaving them strewn with litter.

A woman throws a bottle outside the Congress early Thursday.

Riot police agents arrest a demonstrator outside the Congress.

Opposition mounted ahead of the vote in Argentina's more conservative Senate after the legislation only narrowly passed through the lower house of Congress in June. And the bill lost momentum over the weekend when an opposition senator withdrew her support.

Hopes among supporters were briefly raised when Senator Cristina Fernández de Kirchner, who had refused to address abortion during her two terms as Argentina's president, announced she had changed her mind and would vote for the bill.

"It was the thousands of young women who went out to the streets who made me change my opinion," she told the Senate Wednesday. "To see them criticize the realities of a patriarchal society should force all of us to look at this differently."

Although he opposes abortion, President Mauricio Macri said earlier this year that he would not veto the legislation if it passed.

Protesters demonstrate in support of loosening the abortion law, left, and against abortion, right, in this photo taken from Congress where lawmakers were debating the issue.

Activists in favor of legalizating abortion comfort each other outside the National Congress.

One woman who was demonstrating in favor of abortion rights in Buenos Aires before the vote used Instagram to express her frustration at the result.

"Today no one won," wrote the women who posts under the name Veronnica Diaz. "The abortions WILL KEEP HAPPENING, the women will continue to die in clandestine abortions and your Neanderthal position of 'saving two lives' in a comfortable social inequality will continue without saving ANY LIFE."

Celia Szusterman, trustee of the UK board of Pro-Mujer and director of the Latin America program at the Institute for Statecraft, told CNN that the result was "a step backward for women's rights and women's health."

She says it's a "sad day... not only because of the way the vote went but the way the campaign for and against went. It was so divisive."

Pro-choice activists hold green banners as they demonstrate outside Congress on Thursday.

But even with its defeat, the groundswell of support for the legislation is not expected to go away, with those who supported the bill saying it was a victory that it was even debated.

Activists say they'll keep pushing the bill, in the hope that it passes one day soon.

"It will happen because that's the world -- to increase rights and this is one of the fundamental rights that is still not available to women in Latin America," Szusterman said.

The bill has ignited passions and sparked widespread protests in Argentina, with anti-abortion campaigners protesting in the streets under blue "save both lives" banners and members of the opposing side in the debate donning green bandanas.

As senators debated the bill into the early hours of Thursday morning, pro-abortion rights activists rallied outside Congress chanting "legal abortion at the hospital" while the Catholic Church held a "Mass for Life" in the capital Buenos Aires.

Speaking during the debate, conservative Senator Marta Varela welcomed the mobilization of anti-abortion campaigners.

"Today I feel like never before that I'm part of a wide sector of our people who defend life in general, from the moment of conception and until death," she said.

Pro-choice activists hold a poster of a woman who died as a result of a clandestine abortion.

An activist in favor of legalizing abortion holds a sign reading "Take your Rosaries from our ovaries" during a demonstration outside of Argentina's embassy in Santiago, Chile.

In recent weeks the so-called "green wave" demonstrations have spread outside of Argentina too. Green bandanas -- now a symbol of the abortion rights movement -- have been spotted in Brazil, where the country's supreme court is considering loosening abortion restrictions. And momentum is growing in Chile, where lawmakers voted last year to ease the country's strict ban.

Supporters of the bill rallied across the region Wednesday, in Chile, Uruguay, Mexico and Peru, as well as across the Atlantic, in Spain.

Bolstered by Ireland's referendum in May, which removed one of Europe's last abortion bans, pro-abortion rights activists were hoping they could turn the tide on abortion law in Latin America, where more than 97% of women of reproductive age live in countries with restrictive abortion laws. On Tuesday, 60 Irish parliamentarians, across political parties and groups, signed a letter to the Argentinian senators urging a vote in favor of the bill.

While Pope Francis hasn't addressed the legislation directly, he did speak out strongly against abortion just days after the bill was approved by the lower house -- comparing abortion to avoid birth defects to Nazi eugenics.

The pontiff also issued a letter in March, as the abortion debate began, urging Argentines to "make a contribution in defense of life and justice."