Last night's vote on gay marriage at Holyrood was, in the words of Willie Rennie, the Scottish Liberal Democrat leader, a historic day for equality and an important step towards a fairer society.

It was also evidence of how far attitudes in Scotland have come. As recently as 2000, the Scottish Social Attitudes survey showed almost half of Scots believed sexual relationships between adults of the same sex were always or mostly wrong. By 2010, 61% of Scots said they supported same-sex marriage.

That is a remarkable, and welcome, turnaround in a very short time and some of it is undoubtedly due to the success of civil partnerships. Contrary to the doom-laden predictions of some opponents, the roof did not fall in when civil partnerships were introduced and there have been thousands of such partnerships since the legislation was passed in 2004.

Of course, the issue of gay marriage still has the power to divide. Among those who did not vote for the Marriage and Civil Partnership Bill yesterday was education minister Alasdair Allan, who said that, while he was supportive of civil partnerships, he believed difficult issues were raised around the specific question of marriage. Religious groups, including both the Church of Scotland and the Catholic Church, have also been consistent in their opposition.

It is to the credit of the Scottish Government that it did not ignore this opposition or dismiss it as homophobic and that the same-sex marriage legislation protects those who object on religious grounds. Faith bodies will have to opt in to perform same-sex marriage ceremonies and, if they do, protection will also be offered to individual celebrants who believe it would be contrary to their beliefs to perform the ceremonies.

This is the right approach. The Marriage and Civil Partnership Bill is a measure of the extent to which Scotland has become more free and fair, but freedom of religion and freedom of speech should be protected as well as the freedom to marry someone of the same sex.

We will have to wait and see how the legislation works in practice to determine if those freedoms have been properly balanced and it is likely some of the controversy will linger. Some humanists, for example, are concerned that there is no protection for a celebrant who wishes to carry out gay marriages but cannot because his or her faith group has not opted in. In register offices too there may be an issue with registrars who do not wish to conduct same-sex ceremonies, although this has not proved a problem with civil partnerships.

The early stages of the new law will no doubt throw up any problems, although the early signs are that the legislation is sound. Religious groups should feel satisfied that they will not be forced to carry out gay marriages while gay couples can celebrate a truly remarkable, bold and welcome change to the law. Last night's vote means Scotland will soon join the list of progressive democracies that have legalised gay marriage. It is indeed a historic day. Scotland is a fairer place.