New Zealand's parliament has passed controversial legislation to recognise civil unions between gay couples.
The Civil Union Bill, which passed by 65 votes to 55, also recognises unions between men and women who do not want to marry.
The new law, which takes effect next April, gives unmarried couples the same rights as married couples in areas like child custody, tax and welfare.
The bill stirred fierce debate, with critics saying it undermined marriage.
But the bill's sponsor, David Benson-Pope, denied it undermined marriage or posed a threat to the family.
"Civil union offers an alternative to those [couples]
unable to marry or who prefer not to marry," he said.
The decision came as Canada's Supreme Court prepared to hand down a landmark ruling on whether gay marriage must be allowed across the country.
In a number of countries in Europe, the status of "registered partnership" has been established, including Denmark, Norway and Sweden. Spain has introduced a draft law which will legalise same-sex marriages. And in the US, the state of Massachusetts this year became the first state to issue marriage licences for gay couples. Vermont allows civil unions.
The announcement of result in New Zealand's vote led to cheering and applause in parliament.
Conservation Minister Chris Carter, who is planning a civil union with his partner Peter Kaiser as soon as the law takes effect, told parliament that history was being created.
"Today I sense tremendous joy and enthusiasm. We will have an opportunity we have always been denied," he said.
But opponents of the bill have accused the government of trying to undermine the status of marriage.
Most opposition MPs from the centre-right National Party and the smaller Act Party voted against the bill.
One National MP, Nick Smith, told parliament the legislation was a gay marriage bill in drag.
Another MP in the same party, Brian Connell, said: "The fact around this bill is that it's about homosexual marriage. And the overwhelming view of the people of New Zealand is that they don't want a bar of that."
As a sign of the debate's intensity, a jar of excrement was left outside the electorate office of David Benson-Pope. An openly gay Labour MP, Tim Barnett, received a castration kit through the post.