It will be illegal to conduct gay marriages in the Church of England and Church in Wales under government plans.
Other religious institutions will be able to opt-in to offer same-sex ceremonies but no church will be forced to conduct gay weddings, culture secretary Maria Miller told MPs.
Prime Minister David Cameron supports conducting gay marriage ceremonies in churches but has faced strong opposition - much of it from within his own party.
Miller assured parliament that Roman Catholic churches, synagogues, mosques and other religious buildings would have "watertight" protection if they chose not to conduct gay marriages under a "quadruple lock" to protect religious freedom.
The minister said: "I am absolutely clear that no religious organisation will ever be forced to conduct marriages for same-sex couples and I would not bring in a bill which would allow that.
"European law already puts religious freedoms beyond doubt and we will go even further by bringing in an additional 'quadruple legal lock'.
"But it is also a key aspect of religious freedom that those bodies who want to opt in should be able to do so."
Miller told MPs that, as the Anglican had clearly shown opposition to the plans, the government would "explicitly state that it will be illegal for the Churches of England and Wales to marry same-sex couples" and that canon law, which bans same-sex weddings, would continue to apply.
Under the plans, the four measures that will protect religious freedom are:
- No religious organisation or individual minister of a church can be compelled to marry a same-sex couple or to allow this to take place on their premises.
- Religious ministers will be banned in law from marrying same-sex couples unless the organisation's governing body has expressly decided to do so.
- The Equality Act 2010 will be amended to prevent any discrimination claim being made against religious groups or individuals for refusing to marry a same-sex couple.
- The bill will explicitly make it illegal for the Church of England and the Church in Wales to marry gay couples or to opt in to do so. Parliament and the Church would need to pass explicit laws in favour of gay weddings before any decision could be taken to opt in to same-sex marriage.
The bill on same-sex marriages looks set to be introduced in January, with the first gay wedding likely to take place in 2014.
Both Labour and the Liberal Democrats have backed the plans to allow gay marriages.
However, more than 100 Tory MPs are believed to oppose the idea and are planning to vote against it when Cameron offers a free vote next year.
Stewart Jackson, MP for Peterborough, told Sky News: "This is a mistake. It's a very divisive issue and an unnecessary piece of legislation.
"It is fundamentally an un-Conservative policy and if [Cameron] presses ahead with this it will be a disaster for the party and the country."
Fellow Tory backbencher David Davies added: "We're going to lose a large number of very loyal activists who've gone out and campaigned for us over the years and who don't like this idea. Politically it's barking mad."
However, a number of senior Tory MPs, such as Mayor of London Boris Johnson, education secretary Michael Gove and former prime minister John Major, have publicly backed the move.
Ben Summerskill, chief executive of the gay rights organisation Stonewall, said: "We're delighted about the government's statement today and welcome the promise to legislate for equal marriage as warmly as on the three previous occasions that this announcement has been made.
"We're particularly pleased that ministers have been persuaded to extend their original proposal in order to permit same-sex marriages for those religious denominations that wish to hold them. This is an important matter of religious freedom."