Australia legalized same-sex marriage Thursday, paving the way for the first gay weddings to be held early next year and triggering jubilant celebrations at Parliament House.

Lawmakers and supporters of marriage equality in the public gallery cheered and applauded as the legislation was passed in the lower chamber, three weeks after the public overwhelmingly backed changing the law in a nationwide survey.

“Australia has done it,” Prime Minister Malcolm Turnbull said. “Every Australian had their say and they said it’s fair, get on with it. The parliament has got on with it, and we’ve voted today for equality, for love.”

Australia is the 25th nation to legalize same-sex unions, according to the Marriage Equality campaign group, trailing countries such as the U.K., Ireland and New Zealand. Even though the nation’s largest city, Sydney, has famously held its vibrant Gay and Lesbian Mardi Gras since 1978, regional areas were more reticent to embrace gay marriage and the issue has divided parliament for years.

“This is a wonderful moment in Australian history,” said Tiernan Brady, leader of the Marriage Equality campaign. “The Australian people have reaffirmed that this is a land of the fair go for everybody. For the first time, the LGBTI community feels like a full member of society, which is an incredibly empowering moment.”

Laws discriminating against the gay community have gradually been repealed in Australia over the decades and Tasmania became the final state to decriminalize homosexuality in 1997. Same-sex couples have been recognized in legally binding relationships since 2009.

Thursday’s marriage equality vote ends a protracted and hard-fought campaign by gay-rights activists, who argued that conservative lawmakers on both sides of politics were increasingly out of touch with public opinion. Much of the business community also rallied to the cause, and more than 30 executives this year petitioned the government to change the law.

The impasse was broken by a government-commissioned postal ballot, which last month saw 61.6 percent of respondents back same-sex marriage — a result Turnbull described as “unequivocal.”

Conservative lawmakers had sought to amend the legislation to ensure that celebrants and other service providers couldn’t be charged with discrimination if they refused to marry gay couples on religious grounds. Those amendments were defeated on Thursday.

Turnbull, 63, was criticized by the main opposition Labor party for holding the postal survey instead of pushing for parliament to resolve the issue earlier with a free vote. Since becoming prime minister in September 2015, he has struggled to pursue the socially-progressive agenda many voters expected of him, leading to claims he is beholden to conservatives within his own party.

Critics of the postal ballot said it exposed the gay community to a vitriolic No campaign and led to a surge in calls to mental-health helplines. When the prime minister this week claimed the legislation as a victory for his government, prominent lesbian actress Magda Szubanski accused him of “gloating” and said the survey had caused pain for many LGBTI people.

Australia had about 46,800 same-sex couples in 2016, a 39 percent increase since 2011, according to government figures. The Australian economy will reap a A$650 million ($490 million) windfall in the first year alone through the spin-off benefits from additional weddings, along with a slight boost to confidence, Australia & New Zealand Banking Group Ltd. said in a September report.

After the legislation was passed, politicians approached gay-rights campaigners in the lower-house’s public gallery to applaud them. The supporters then flooded out to celebrate in other areas of Parliament House, some quaffing champagne and singing “we’re going to the chapel and we’re going to get married.”

For activists such as Brady, who also led the successful 2015 referendum to legalize same-sex marriages in Ireland, the fight for equality will go on.

“Australia and New Zealand are the only two nations east of Jerusalem that have marriage equality,” said Brady. “That means there are around 4 billion people without these rights that Australians will now enjoy, so there’s a lot more work to do.”

Follow the Bangor Daily News on Facebook for the latest Maine news.