The decision could echo across Latin America, where the Roman Catholic Church has lost influence and moral authority due to secularization, an out-of-touch clerical caste and an avalanche of sex abuse scandals.
The Morning Rundown
Get a head start on the morning's top stories.
Thousands of supporters wearing green handkerchiefs that represent the effort to legalize abortion and opponents of the measure wearing light blue, braved the heavy rain and cold temperatures in Argentina's winter to watch hours of the debate on large screens set up outside Congress.
The demonstrations were largely peaceful, but after the vote, small groups of protesters clashed with police, throwing firebombs and setting up flaming barricades. Police officers responded with tear gas.
In Argentina, abortion is only allowed in cases of rape and risks to a woman's health. If passed, the bill would have allowed for elective abortion up to two weeks gestation.
The lower house had already passed the measure and conservative President Mauricio Macri had said that he would sign it, even though he is anti-abortion.
Thousands of women, most of them poor, are hospitalized each year for complications linked due to unsafe abortions — the main cause of maternal death.
Backers of the measure said legalizing abortion would save the life of many women who now turn to dangerous illegal abortions. The Health Ministry estimated in 2016 that the country sees as many as half a million clandestine abortions each year, with dozens of women dying as a result.
Activists estimate that 3,000 women in Argentina have died of illegal abortions since 1983.
The Catholic Church and other groups opposed legalizing the termination of pregnancy, saying it violated Argentine law, which guarantees life from the moment of conception.
Pope Francis this year had denounced abortion as the "white glove" equivalent of the Nazi-era eugenics program and urged families "to accept the children that God gives them."
Uruguay and Cuba are the only Latin American countries that now have broadly legalized abortion.