Civil partnerships were legalised in England and Wales in 2004
Peers have voted to lift the ban on same sex couples holding civil partnership ceremonies inside churches.
The House of Lords agreed an amendment to the Equality Bill which would allow, but not compel, religious organisations to host the occasions.
Gay rights campaigners celebrated the change, but opponents said it could be impractical and undermine marriage.
Peers voted by a majority of 74 in favour of the amendment, which was not backed by the government.
It is yet to be approved by the Commons, but it is thought to be unlikely that MPs would make any significant changes.
Labour peer Lord Alli proposed the amendment, telling the Lords: "There are many gay and lesbian couples who want to share their civil partnership with the congregations that they worship with.
"And there are a number of religious organisations that want to allow gay and lesbian couples to do exactly that."
He said: "In the end it comes down to an issue of religious freedom."
It was not an "attack" on the Church of England or the Catholic Church, he added.
Lord Alli said: "Religious freedom requires us to let others do things that we ourselves would not do. Religious freedom cannot begin and end with what one religion wants."
Lords leader Baroness Royall and Conservative equality spokesman Baroness Morris of Bolton, a Roman Catholic, both spoke against the amendment but later abstained.
Lady Royall warned of potential practical difficulties which would have to be addressed in later regulations.
Ben Summerskill, chief executive of gay rights group Stonewall, said: "We are absolutely delighted with this vote for religious freedom. It will be warmly welcomed by lesbian and gay people of faith.
"We regret the government spoke against equality but we hope they will now do the necessary drafting with urgency."
Lord Alli's cross-party amendment was co-sponsored by Tory finance spokesman Baroness Noakes, retired judge and crossbench peer Baroness Butler-Sloss and crossbencher Baroness Campbell of Surbiton.
But the Bishop of Bradford, the Rt Rev David James, who voted against the amendment, warned of "unintended consequences".
He said: "When we consider changes to the law, we need to be clear about what they are meant to achieve and what, in practice, they do achieve."
He said there had been "no practical difficulties so far" with the existing legislation, adding: "The fundamental difficulty that many churches and faiths will have with this arguments is that we, like the government and the courts, have been quite clear ever since civil partnerships were introduced that they are not the same as marriage."
Other opponents included Conservative former cabinet ministers Lord Tebbit and Lord Waddington.
A Government Equalities Office spokesman said: "Baroness Royall made the government's position clear during the debate; we're now considering what steps to take next."
Civil partnerships were legalised in England and Wales by the Civil Partnership Act of 2004, which came into force the following year.