Gay rights advocates praised the landmark vote even as they said it was long overdue. In a country where there had been 22 unsuccessful attempts in Parliament to legalize same-sex marriage since 2004, they said, the law should be seen as the triumph of a democracy learning to live up to its values.
“This is a big victory,” said Evan Wolfson, the founder of Freedom to Marry, which led the campaign for marriage equality in the United States. “It is a huge affirmation of the dignity of gay people in yet another country, and that will reverberate in the lives of people across Australia and the world.”
A handful of lawmakers tried to add amendments that they said were meant to safeguard religious freedoms for opponents of same-sex marriage, but their efforts failed. Mr. Turnbull noted that nothing in the legislation requires ministers or other celebrants to oversee weddings of gay couples or threatens the charity status of religious groups that oppose same-sex marriage, two concerns the lawmakers had raised.
The final debate in the House of Representatives featured more than 100 speakers.
On the first day, there was a marriage proposal: Tim Wilson, a gay member of Parliament with the center-right Liberal Party, spoke of the struggles he and his partner, Ryan Bolger, had encountered as a couple, before choking up, finding him in the public gallery and asking: “Ryan Patrick Bolger, will you marry me?”
The answer came loud and clear — “yes” — as did public congratulations from the deputy speaker, Rob Mitchell.
That was followed by hours of emotional speeches, as politicians on the left and right fell into a rare moment of relative consensus and moving closer to public sentiment, which has favored same-sex marriage for years, according to polls.
Even former Prime Minister Tony Abbott, a staunch critic of same-sex marriage, seemed to have softened.
“When it comes to same-sex marriage, some countries have introduced it via the courts, some via Parliament, and others — Ireland and now Australia — by vote of the people,” Mr. Abbott said. “And that is the best way because it resolves this matter beyond doubt or quibble.”
For many lawmakers and gay-rights advocates working behind the scenes, the debate took on the feel of a communal reckoning with Australia’s long history of homophobia.
At one point, Adam Bandt, a Greens Party lawmaker from Melbourne, paused for a moment of silence after referring to the “innocent blood” of gay Australians who were hurt during the long battle for marriage equality.
Bill Shorten, leader of the opposition Labor Party, asked for forgiveness “for the long delay, for the injustices and the indignities both great and small.”
He also paid tribute to a Labor Party colleague, Senator Penny Wong, a gay politician who he said had walked “a lonely road and a hard road” to help change Australia.
Passage came just weeks after 61 percent of voters in a nonbinding national referendum, conducted by mail, expressed support for same-sex marriage. Advocates for gay marriage assailed the Turnbull government’s decision to hold the referendum, calling it a delaying tactic intended to appease his party’s far-right faction.
“Our very identity has been the subject of public scrutiny and public debate,” Senator Wong said after the referendum results were announced. “Through this campaign, we have seen the best of our country and also the worst.”
At her office in Parliament House this week, Ms. Wong said Mr. Turnbull’s decision to pursue the referendum had unleashed a campaign of fear-mongering and hate that she would struggle to forgive.
“It is a hard thing to have others judge whether you deserve to be equal,” she said. “And it is an even harder thing to have your family and your children besmirched by those who want to perpetuate discrimination.”
Many other gay Australians said they had been hurt and frustrated by the referendum process.
“The conversation around marriage equality was being dominated by those who were against it,” said Tristan Meecham, the artistic director of the performance company All the Queens Men and the founder of the Coming Back Out Ball, meant to encourage older gay Australians not to return to the closet.
Left out of the discussion, he added, were issues that go beyond marriage, such as the way older men and women deal with earlier traumas tied to prejudice and gay bashing, or suicide among teenagers dealing with issues of gender and sexuality.
“People need to realize that marriage is a certain thing for a certain part of the community, but the real social mission behind all of this is equality,” Mr. Meecham said. “And there is a lot of work that still needs to be done.”
Still, he said, he could not deny the sense of validation that the process had delivered.
“There’s a breathing process,” he said, “a relief, a cleansing.”
In Parliament after the vote, there was mostly jubilation and relief.
Hamish Taylor, 22, from Melbourne, walked out of the gallery and embraced his best friend in a bear hug. “I’m absolutely gobsmacked,” he said. “My heart is beating out of my chest. This debate has been in my life ever since I knew I was gay.”
Of the result, he said, “It’s alleviated a life of shame and embarrassment of who I am,” adding: “It’s just validated everyone’s love here and around Australia.”
In many countries where same-sex marriage is already legal, the tangible effects of institutional acceptance have become more visible, and positive, studies have found.
One study published earlier this year, in the journal JAMA Pediatrics, found that reducing societal stigma through marriage legalization had led to a 14 percent reduction in suicide attempts among lesbian, gay and bisexual teenagers.
Mr. Wolfson said that in both the United States and Spain, which legalized same-sex marriage in 2005, polls have found support for same-sex marriage growing instead of diminishing, a sign of the laws’ positive effects.
“Families are helped and no one is hurt,” he said. “The evidence is overwhelming.”
For now, though, Australia is more focused on the immediate, with the first legal same-sex weddings expected in early January.
In his chambers the day after proposing to his partner, Mr. Wilson seemed exhausted and relieved. He said that after many false starts, he was thrilled to finally be getting married in his hometown, Melbourne, early next year.
“People kept saying go and get married overseas, and we always took a very firm view that we couldn’t do that,” Mr. Wilson said. “We had to get married in our home city.”
He predicted a small, private and proud celebration.