Argentina has become the first country in Latin America to legalise gay marriage.
The decision was approved 33 votes to 27 by the Argentine Senate in the form of a bill that also allows same-sex couples to adopt children.
The lower house, the Chamber of Deputies, had already approved the legislation, which was backed by President Cristina Fernandez's centre-left government.
The proposed law change had met with fierce opposition from the Catholic Church and other religious groups. Outside Congress, as the debate continued into the early hours of Thursday, supporters and opponents of the bill held rival demonstrations.
The BBC reports that there have been several gay marriages recently in Argentina, some of which were annulled by the Supreme Court, creating a legal controversy.
Civil unions between people of the same sex are legal in Buenos Aires and in some other provinces but up to now there was no law to regulate it on a country-wide level.