The Roman Catholic Church had led mass demonstrations against the bill, with its officials describing it as "the devil's project".
On Wednesday police had to separate opposing groups protesting outside the Senate who hurled eggs and oranges at each other.
Adolfo Rodriguez Saa, former president, said: "Argentina has taken a step forward, but out in the street ... it will take time for hatred and resentment to heal."
The law is sure to bring a wave of marriages by gays and lesbians who have increasingly found Buenos Aires to be more accepting than many other places
in the region.
Nine gay couples had already married in Argentina after persuading judges that the constitutional mandate of equality supports their marriage rights,
but some of these marriages were later declared invalid.
Same-sex civil unions have been legalised in Uruguay, Buenos Aires and some states in Mexico and Brazil, while Mexico City has legalised gay marriage.
Colombia's Constitutional Court granted same-sex couples inheritance rights and allowed them to add their partners to health insurance plans.
But Argentina now becomes the first country in Latin America to legalise same-sex marriage nationwide, granting gays and lesbians all the same rights
and responsibilities that heterosexuals have.
These include many more rights than civil unions, including adopting children and inheriting wealth.
Gay rights advocates said Argentina's historic step adds momentum to similar efforts around the world.