BUENOS AIRES — Proponents of legalizing abortion in Argentina celebrated on Thursday as the lower house of Congress narrowly approved a contentious bill that would allow women to terminate pregnancies during the first 14 weeks.

Hours after women popped open bottles of Champagne and shed tears of joy outside Congress following the 129-to-125 vote, several key members of the upper chamber announced that they would support the measure.

By the end of the day, backers of the legislation believed they had gained the upper hand in a debate that unexpectedly moved to the top of the political agenda in recent months as women’s rights groups staged large rallies around the country.