Jerry Slater and Larry Lamont from Kircudbright, who are in a civil partnership and plan to marry under the new legislation, kiss outside the Scottish parliament. Photograph: Ken Jack/Demotix/Corbis

The first same-sex weddings in Scotland could take place in October after MSPs voted by a majority of 87 to legalise gay marriage.

The vote, passed by 105 to 18, came after the Scottish parliament voted down several attempts to amend the bill to add extra protections for religious celebrants who opposed the new law.

The amendments were backed by up to 21 MSPs, chiefly Catholic and Baptist churchgoers, but Alex Neil, the Scottish health secretary, argued there were already "robust protections" for religious organisations and celebrants.

"We have always maintained at the heart of this issue there is one simple fact: a marriage is about love," Neil said. "All couples in Scotland in a loving relationship must know that they have the same rights and responsibilities and, regardless of their gender, the same opportunity to get married."

Religious bodies will be allowed to carry out same-sex weddings if they formally opt in to the legislation; individual celebrants who still reject the reform after their churches introduce it will be protected, after the UK government agreed amendments to the Equalities Act.

Gay and civil rights campaigners were jubilant with the result. Tom French, policy co-ordinator for the Equality Network, said: "This is a profoundly emotional moment for many people who grew up in a country where being gay was still a criminal offence until 1980.

"Scotland can be proud that we now have one of the most progressive equal marriage bills in the world, and that we've sent out a strong message about the kind of country we are."

Colin Macfarlane, director of Stonewall Scotland, said it was a historic moment. "We're delighted that MSPs have overwhelmingly demonstrated that they're committed to building a Scotland fit for the 21st century," he said.

Scotland will become the 17th country and legislature around the world to introduce same-sex marriage. The first in England and Wales are due to take place this March.

Scotland's first marriages are expected this autumn, after ministers promised to rush through the legal powers.

The two main churches, the Presbyterian Church of Scotland and the Roman Catholic church, have opposed the reform, alongside other faiths and churches including Muslim leaders. More than 50 ministers and church officials wrote to the Scottish government expressing their "deep concern" before the vote. The multi-faith Scotland for Marriage group said more than 54,000 people had signed a new petition opposing the law by Monday evening.

Opponents of the measures fear that equalities legislation could be used to force public servants such as registrars or schoolteachers to support gay marriage. Christian MSPs pressed for clauses stating "for the avoidance of doubt" that marriage is "between one man and one woman".

They believe churches could be refused funding or council buildings if they are known to oppose same-sex marriage. John Mason, an SNP MSP and Baptist, tabled several amendments to bolster the statutory rights of opponents of same-sex ceremonies, including one stating that no one could be "compelled by any means" to solemnise a gay marriage.

"If the parliament accepts none of these amendments this afternoon, we are sending out a signal that we've not been listening," Mason argued.

Richard Lyle, another SNP MSP, said prospective foster carers could be turned down if they opposed same-sex marriage. "What is more likely, yet not less tragic, is that applicants with so-called traditional views on marriage will be put off applying in the first place, fearing they will be branded homophobic," he said.

That argument was resisted by Jim Eadie, also an SNP MSP. "Speaking as someone who is both gay and adopted, I believe this amendment is both discriminatory and unnecessary because it singles out beliefs about same-sex marriage of being worthy of protection. Why should other beliefs not be similarly protected, for example a belief that divorce is wrong."

Jackson Carlaw, the Scottish Tory deputy leader, said there was a "celebratory attitude" during the Holyrood debate, and wholeheartedly supported the new legislation.

"There has been a huge change in my lifetime, from the brutal atmosphere that existed in respect of gay people when I was a teenager and a young man," he said. "But I regard today as a fantastic, celebratory change in the mood, style, signature and stamp of my country, Scotland."