The lower house of Argentina’s congress has narrowly approved a bill that would legalise abortion in the first 14 weeks of pregnancy, in a historic victory for the country’s growing women’s movement.

Tens of thousands of women – many wearing the green headscarfs which have become a symbol of the movement – braved a freezing winter night to stand vigil outside the congress building in Buenos Aires during the marathon 20-hour debate.

The bill was finally passed early on Thursday by 129 votes to 125, paving the way for Argentina to become the third nation in Latin America – after Cuba and Uruguay – to legalise abortion.

It will now go before the country’s upper house, where it will face another tough battle. The centre-right president, Mauricio Macri, has declared himself personally against legal abortion, but has pledged to sign the bill into law if it is passed.

“It was a long night for those of us who were in the plaza, we did not sleep at all – old women, young women, forming a green tide,” said Julieta Ortega, a prominent member of the Argentinian Actresses Collective which had campaigned tirelessly for the reform. “Today we are a fairer country. We are very happy for us and for the young girls of today who will become the women of the future,” she said.

Argentina has long had some of the world’s most restrictive abortion laws: even in cases where it is allowed by law – in the case of rape, or when a woman’s life is in danger – doctors are often unwilling to proceed with a termination for fear of prosecution.

But campaigners have argued that the ban only pushes women to seek unsafe clandestine terminations, a major cause of maternal mortality.

Mariela Belski, Amnesty International executive director in Argentina, welcomed the move. “New legislation could end a vicious circle where women have no option but to risk their lives, their health, and their freedom if they are sent to prison,” she said.

At the all-night vigil, campaigners watched the debate inside congress on giant screens. Some brandished posters of Eva Perón, who is still considered by many as a hero of the country’s women’s movement.

“This is a great victory for the expansion of rights and in the fight for women’s equality. Once again Argentinian civil society is the driving force behind state policies that promote respect for human rights,” said Gastón Chillier, the executive director of the Centre for Legal and Social Studies (CELS).

“The women who organised themselves against the dictatorship four decades ago, such as the Mothers and Grandmothers of Plaza de Mayo, paved the way for the powerful women’s movement today in Argentina.”

The vote – which would have been unthinkable even a year ago – comes after a shift in public opinion driven by a new generation of female activists who have highlighted the many cases of women who died after undergoing clandestine abortions.

Campaigners compared the result to a victory for Argentina at the World Cup.

“This is our World Cup, but there are many matches still left ahead,” said María Virginia Godoy – better known as Señorita Bimbo – a comedian and activist whose appearances on prime time television helped raise public awareness of the issue.

“There’s no going back, this is no longer the same Argentina as before. If we can organise ourselves for other issues like we did for this one, can you imagine the difference it would make? We could have whatever world we wanted,” she said.

Argentina remains a deeply conservative society and the bill was opposed by the Argentinian-born Pope Francis and politicians in the government and opposition.

Jon O’Brien, president of Catholics for Choice, said: “As Ireland, and Chile before it, have demonstrated, Catholics can be and often are pro-choice. And indeed Catholic-majority countries can and often do support legislation for safe and legal abortion. Catholics revere individual conscience and support policies that allow all women – especially those without power and privilege – to make their own moral decisions about their bodies safely and freely.”

The vote also sends a strong signal across the region. Campaigners in El Salvador and the Dominican Republic have renewed efforts to relax abortion laws in their countries – but in neighbouring Brazil, legislators tied to the powerful evangelical caucus are considering even tougher abortion laws, including jail terms of up to four and a half years for women who abort fetuses with microcephaly.