The Kirk has voted by just over two to one to take steps which could lead to ministers and deacons being allowed to carry out gay marriages.
The key decision at the Church of Scotland’s General Assembly will see a committee tasked with drawing up rules on how same sex marriages could be carried out within the church.
But commissioners agreed it should only act if, in its opinion, safeguards “sufficiently protect against the risks they identify”.
The move comes around a year after the Scottish Episcopal Church’s decision to permit its ecclesiasts to perform gay marriage ceremonies - the first mainstream church to do so.
The game-changing Holyrood Bill which led to legislation permitting gay marriage won overwhelming support four years ago, when 105 MSPs voted in favour while just 18 were against.
However in Falkirk while Michael Matheson MSP voted for, Falkirk East MSP Angus MacDonald abstained.
This week’s motion calling for legislation to be prepared was put forward by Rev Bryan Kerr, minister of Greyfriars Parish Church in Lanark.
It was amended to ensure the committee had the power to recommend withdrawal following a call from Rev Peter White of Sandyford Henderson Memorial Church in Glasgow.
Later, Mr Kerr said: “I am delighted that that the General Assembly continues on a road where we are able to say to people in same-sex relationships that the Church has a place for you.
“I am pleased we have reached this point and I have already had reaction from parents of people in same-sex relationships who are overwhelmed that the Church accepts that God loves them.
“It was clear from the floor of the Assembly that many commissioners appreciate having a choice with their families as to whether they act as minister or a parent of the bride or groom.”
However Rev Mark Malcolm, a meember of evangelical Kirk group Covenant Fellowship Scotland, said: “From those of us who want to uphold the traditional and orthodox teaching of the Church, it is possibly as good an outcome as we could expect.
“Looking into the future, I think what is likely to happen is instead of the default position of the Church being orthodox and traditional it will be revisionist -and you will have to opt in to the orthodox position rather than holding that position”.
He added: “This has not been a happy or peaceful process and people are largely weary and tired of this debate.
“They just want to get on with what it means to be the Church and proclaim the Gospel.”
The committee charged with drafting Kirk rules on gay marriage will report back in 2020.