The Australian Parliament voted on Thursday to allow same-sex marriage across the nation, following a bitter and divisive debate settled by the government polling voters in a much-criticized ballot survey that strongly endorsed change.

The public gallery of the House of Representatives erupted with applause when the bill passed to change the definition of marriage from solely between a man and a woman to "a union of two people" excluding all others. The legislation passed with a majority that wasn't challenged, although five lawmakers registered their opposition to the bill.

The Senate passed the same legislation last week 43 votes to 12. After formalities the law will likely take effect in about a month, with the first weddings expected about a month later.

Gay marriage was endorsed by 62 percent of Australian voters who responded to the government-commissioned postal ballot.

The Morning Rundown Get a head start on the morning's top stories. This site is protected by recaptcha

Most gay rights advocates believed the government should have allowed marriages years ago and saw various ideas for a public survey as a delaying tactic. The U.N. Human Rights Committee had called the ballot survey "an unnecessary and divisive public opinion poll."

Amendments meant to safeguard freedoms of speech and religion for gay-marriage opponents were all rejected, though those issues may be considered later. The government has appointed a panel to examine how to safeguard religious freedoms once gay marriage is a reality in Australia.

Lawmakers advocating marriage equality had argued that the national postal survey in November mandated a change of the marriage definition alone, so changing the law should not be delayed by other considerations.

"It's an historic day for Australia today and I think the celebrations around the country when we finally ... achieve marriage equality are going to be immense," Janet Rice said before the vote. Rice is a minor Greens party senator who was only able to remain married to her transgender wife of 31 years, Penny, because Penny remained listed as male on her birth certificate.

Penny Wong, an opposition Labor Party senator who has two children with her lesbian partner, said: "I am feeling happy."

Liberal lawmaker Warren Entsch lifts up Labor lawmaker Linda Burney as they celebrate the passing of the Marriage Amendment Bill on Thursday. LUKAS COCH / EPA

The current bill allows churches and religious organizations to boycott gay weddings without violating Australian anti-discrimination laws.

One of the rejected amendments would have ensured Australians could speak freely about their traditional views of marriage without fear of legal action.

Veteran gay rights campaigner Rodney Croome said he expected the first same-sex weddings in Australia would not take place until February.