The laws, which will also recognise same-sex marriages carried out in foreign countries, take effect from Saturday. Because a month's notice is required for the state to recognise a marriage, the first legal same-sex unions will be in January.
Lawmakers, who had cast aside a conservative push to allow religious objectors to refuse service to same-sex couples, waved rainbow flags and embraced in parliament, where earlier in the debate a politician had proposed to his same-sex partner.
Here are some facts about same-sex marriage around the world:
* Same-sex marriage is legal in 26 nations: Argentina, Australia, Belgium, Brazil, Britain, Canada, Colombia, Denmark, Finland, France, Germany, Greenland, Iceland, Ireland, Luxembourg, Malta, Mexico, Netherlands, New Zealand, Norway, Portugal, South Africa, Spain, Sweden, Uruguay, United States.
*It is also set to become legal soon in Austria and Taiwan, following court rulings on the matter this year.
* The first country to legalise same-sex marriage was the Netherlands in 2001.
* Some Australian states ruled homosexual acts to be illegal until just 20 years ago.
* In Africa, where homosexuality is a crime in many countries and can lead to imprisonment or the death penalty, South Africa alone has granted the same access to gay couples. Same-sex marriage legislation came into force there in 2006.
* No countries in Asia allow same-sex couples to marry or enter civil unions of any kind. In May, Taiwan's constitutional court ruled that same-sex couples have the right to legally marry, the first such ruling in Asia.
* Almost one in three adults globally believe people of the same sex should be allowed to marry, a survey of almost 100,000 people in 65 countries showed in 2016.
Sources: International Lesbian, Gay, Bisexual, Trans and Intersex Association or ILGA, Pew Research Center, Reuters.