Scotland has followed England and Wales in changing the law to allow same-sex couples to marry.
The Marriage and Civil Partnership (Scotland) Bill passed its third stage in a free vote at the Scottish Parliament as MSPs voted 105-18 in favour.
The vote means Northern Ireland is now the only country in the UK that does not permit gay people to marry.
After the vote was passed, Scottish Health Secretary Alex Neil said: "This is a historic moment for equality in Scotland.
“I am proud that the Scottish Parliament has taken this progressive and hugely important decision in favour of equal rights in our country.
“It is right that same sex couples should be able to freely express their love and commitment to each other through getting married. Marriage is about love, and that has always been at the heart of this issue.
“That was the clear message from Scotland’s Parliament today. We must no longer allow same sex couples who wish to get married to be barred from doing so.
“Thanks to this bill, same sex couples now have the same access to marriage — one of our most important institutions — as everyone else.
“There has been overwhelming support for this Bill from the beginning and many MSPs from across the political spectrum have expressed considered, personal opinions.
“We now need to work quickly and in close co-operation with Westminster on implementation. On that basis, I very much look forward to seeing the first same sex marriages taking place in Scotland as soon as is possible.”The issue had polarised public opinion between supporters who championed it as a move towards equality and opponents who raised concerns about the impact on religious freedom.
Scotland becomes the 19th country in the world in which gay marriage is permitted in all or part of its jurisdiction. Legislation to allow gay marriage in England and Wales was passed at Westminster in July 2013.
Same-sex marriage is also legal in Argentina, Denmark, The Netherlands, South Africa, Belgium, New Zealand, Spain, Brazil, France, Norway, Sweden, Canada, Iceland, Portugal and Uruguay. In the United States and Mexico marriage is regulated at a state level, with some states allowing same-sex marriage and others restricting the right to opposite-sex couples.
The Scottish Parliament's Bill also allows couples to convert their civil partnerships to marriages.
Critics attempted to add last-minute amendments to extend protections to religious groups.
SNP MSP John Mason had hoped to alter the legislation to ensure no one is "compelled by any means" to solemnise gay marriage.
His was the first of a series of backbench amendments seeking to bolster protection in the Bill for freedom of expression.
"If the Parliament accepts none of these amendments this afternoon, we are sending out a signal that we've not been listening," he argued.
However, the Scottish Health Secretary said the legislation already protected celebrants who do not want to take part in ceremonies.
Mr Neil conceded that churches have concerns, but told the Scottish Parliament: "There are robust protections for religious bodies and celebrants in the Bill and in the planned amendments to the Equality Act."
Mr Mason's amendment was defeated in a 96-21 vote as MSPs picked their way through the final stage of the Bill before it can become law.
As politicians debated in the parliament, supporters rallied outside ahead of the vote.
The Humanist Society of Scotland marked the occasion by offering to conduct free conversion ceremonies for the first 100 same-sex couples who want to be married but are currently in civil partnerships.
Humanist celebrant Ross Wright said: "I've had the privilege of conducting wedding ceremonies for both heterosexual and homosexual couples, and for me, the only difference has been the gender of the dolls on the cake."
More than 50 ministers and church officials wrote to the Scottish Government at the weekend to express their "deep concern" over the proposed law.
Scotland for Marriage, a group set up to oppose the Bill, said more than 54,000 people had signed its petition by Monday evening.
In total, 105 MSPs voted Yes. There were no abstentions but five MSPs did not vote.