Senators voted in favour of the bill after a marathon session with 38 in favour, 29 against and one abstention.
Until now, abortions were only permitted in cases of rape or when the mother's health was at risk.
The bill had been approved by the Chamber of Deputies earlier this month.
The Catholic Church, which remains highly influential in Latin America, had opposed the move, calling on senators to reject the bill supported by centre-left President Alberto Fernández.
Pro-choice activists hope the passing of the law in Argentina - one of the largest and most influential countries in the region - will inspire other countries to follow suit.
Large crowds of campaigners both for and against abortion had gathered outside Congress in the capital Buenos Aires, following the debate on huge screens.
When the vote finally happened in the early hours of Wednesday, there was jubilation in the pro-choice camp.