Senators voted in favour of the bill after a marathon session with 38 in favour, 29 against and one abstention.
The law is groundbreaking for Latin America, a region which has some of the world's most restrictive abortion laws.
The bill had already been approved by the Chamber of Deputies and is backed by President Alberto Fernández.
The passing came two years after senators narrowly voted against legalising abortion.
Large crowds of campaigners both for and against abortion had gathered outside Congress to try to sway undecided senators.
https://www.bbc.com/news/world-latin-america-55475036