A bill which allows same-sex weddings to take place in Scotland has been passed by MSPs in the Scottish Parliament.
MSPs voted by 105 to 18 in favour of the Marriage and Civil Partnership (Scotland) Bill.
The Scottish government said the move was the right thing to do but Scotland's two main churches were opposed to it.
The first gay and lesbian weddings could take place this autumn.
Religious and belief bodies can "opt in" to perform same-sex marriages.
Ministers said no part of the religious community would be forced to hold such ceremonies in churches.
During a debate at Holyrood, MSPs rejected amendments which were said to provide "protection" for groups and individuals opposed to same-sex marriage.
The SNP's John Mason tabled an amendment stating that no-one could be "compelled by any means" to solemnise gay marriage, including by a contract or a legal requirement.
Mr Mason said that this was similar to a measure included in the bill passed by the UK Parliament allowing same-sex marriage in England and Wales.
Health Secretary Alex Neil insisted there were "robust protections for religious bodies and celebrants" in the bill and the amendment was unnecessary.
Mr Mason tabled further amendments, including one calling for recognition that "a belief in marriage as a voluntary union between one man and one woman to the exclusion of all others for life is a belief worthy of respect in a democratic society".
He said: "This has been the prevailing view in Scotland for centuries, and may now be considered a minority view or even old fashioned, but it is an integral tenet of faith for many Christians, Muslims and others as well as the belief of many of no faith position at all."
Mr Mason added: "We have seen volunteers in the third sector removed from the board for publicly supporting traditional marriage."
The first same-sex weddings in England and Wales will take place from 29 March, in the wake of legislation already passed by the Westminster parliament.
In Scotland, same-sex couples currently have the option to enter into civil partnerships, but SNP ministers brought forward their Marriage and Civil Partnership Bill, saying the move was an important step for equality.
MSPs were allowed a free vote, rather than along party lines.
'Not far enough'
Mr Neil said passing the bill meant "a historic day in the history of the Scottish Parliament", which received the front-bench backing of Labour's Jackie Baillie and Conservative Jackson Carlaw.
Gay rights organisations, including the Equality Network and Stonewall Scotland, and a range of other groups, have supported the legislation.
But the Scottish Catholic Church and Church of Scotland oppose the move, and have said they have no plans to conduct same-sex marriages.
And the campaign group Scotland for Marriage said the safeguards in the bill did not go far enough.
Key measures in the Scottish government's bill include:
- Religious and belief bodies opt in to perform same-sex marriage.
- Civil marriage ceremonies can take place anywhere agreed by the registrar and the couple, other than religious premises.
- Celebrants who are part of an organisation which has not opted in would not be allowed to conduct same-sex marriages.
- Individual celebrants who felt it would go against their faith to carry out same-sex weddings would be protected.
- Establishing belief ceremonies, such as humanist ceremonies as a "third form of marriage", alongside religious and civil events.
- Authorising Church of Scotland deacons to solemnise opposite sex marriage.
- Possible tests for religious and belief bodies to meet when solemnising marriages or registering civil partnerships, in light of increasing concerns over sham and forced marriages.
- Introducing religious and belief ceremonies to register civil partnerships.
- Allowing transgender people to stay married, rather than having to get divorced, when obtaining a Gender Recognition Certificate.
- Provision making it clear that the introduction of same-sex marriage has no impact on existing rights to freedom of speech and that it is possible to oppose same-sex marriage "without being homophobic".
- Amended guidance on the teaching of the issue in schools.
- And an intention to recognise same-sex marriages registered elsewhere in the UK and overseas.
Quakers have campaigned in favour of same-sex marriage and have said they would allow ceremonies to take place on their premises.
Other religious groups which back change include Buddhists and the Pagan Federation.
The Church of Scotland - whose ruling General Assembly last year voted to allow actively gay men and women to become ministers - has said the institution stood against homophobia, but added that the "wide spread of opinion" on gay marriage was reflected among members of congregations across the country.
As well as the main bill, Scottish ministers have also reached an agreement with the UK government for an amendment to the 2010 Equality Act.
The move aims to protect individual religious celebrants, who do not wish to conduct same-sex marriages, from the threat of court action claiming discrimination.
Westminster's Marriage Act which became law last July, will allow religious organisations to "opt in" to offering weddings, with the Church of England and Church in Wales banned in law from doing so.
The Church of England, the Church in Wales and other faith groups have stated their opposition to gay marriage.
A report commissioned by the Church of England has recommended that members of the clergy should be allowed to offer blessings to same-sex couples.
The Northern Ireland Assembly is not currently considering any legislation to allow same-sex marriage.
The Scottish government's marriage bill was brought forward after a government consultation, which produced a record 77,508 responses.