The House of Lords has approved the government's plans to allow equal marriage in England and Wales.
Campaigners celebrated outside parliament as the result of the historic vote was announced.
The legislation now goes back to the House of Commons for MPs to consider changes made to it by the Lords.
With the Commons due to begin its summer recess on Thursday, it is likely the proposals will become law within a matter of days.
Welcoming the outcome of the vote, in which the plans were approved by a majority of 242, the government's equalities spokeswoman Baroness Stowell of Beeston said the legislation was a "force for good ".
As dozens of supporters in the Lords wore pink carnations, Lord Alli said he was "truly humbled" by being part of the legislative process.
Having been a peer for 15 years, he said: "As a gay man over those 15 years you have changed my life.
"You have given me dignity where there was sometimes fear. You have given me hope where there was often darkness and you have given me equality where there was sometimes prejudice.
"This is a special place and I am proud to have figured in it."
Liberal Democrat QC Lord Lester of Herne Hill said it would have been "quite inconceivable" for the Lords to have approved such legislation 20 years ago.
"It would have been fairly impossible 15 years ago," he said. "What has changed for the better has been the modernisation through appointments to this House."
Lord Lester said this process had secured a House which was "truly concerned with protecting the rights of minorities" against abuse of power.
But some members of the House of Lords expressed their disappointment with the outcome.
Tory Lord Framlingham complained that the "ill-thought through" legislation had been "bulldozed" through parliament without any real concessions to its opponents. "Happiness won at the expense of other people's happiness is rarely trouble-free in the long term," he warned.
The Bishop of Norwich, the Rt Rev Graham James, said it was "no secret" that the majority of Christian churches and other world faiths "don't believe same-sex marriage accords with their understanding of marriage itself".
But he added: "Many of us do welcome the social and legal recognition of same-sex partnerships and believe our society is a better and healthier one for such recognition."
The first same-sex marriages are expected to take place in England and Wales in 2014.
A bill introducing similar legislation in Scotland was published in June, with equal marriage expected to become law in 2015.
Attempts by members of the Northern Ireland Assembly to approve equal marriage have so far been defeated.