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.