The Church of Scotland has voted in favour of allowing openly gay men and women to become ministers - whilst maintaining a traditionalist standpoint.
The General Assembly backed a motion affirming the Church's "current doctrine and practice in relation to human sexuality", but permitting liberal congregations to depart from that approach if they wish to do so.
The decision, made following a lengthy debate on the issue, will come back before next year's General Assembly for further analysis.
The ordination of ministers in same-sex relationships has divided the Church for many years, with the two sides of the debate broadly characterised as traditionalist or the more liberal "revisionist".
The Church had been expected to vote for one of three options today: to reject the future ordination of ministers in same-sex relationships, to treat openly gay ministers in the same way as heterosexual clergy, or to allow congregations to appoint ministers in civil partnerships whilst permitting individual congregations to opt out.
In fact, the Church voted in favour of a last-minute option brought to the table by a former Church irk moderator, the Very Reverend Albert Bogle.
Church commissioners backed his motion to "affirm the Church's historic and current doctrine and practice in relation to human sexuality, (but) nonetheless permit those Kirk Sessions who wish to depart from that doctrine and practice to do so".
Monday's historic vote effectively means that the traditionalist position holds, but congregations will be able to choose themselves to have a minister in a civil partnership if they wish to do so.
Such a move will require certain Church regulations to be written and voted on at the 2014 General Assembly.
Mr Bogle's motion was carried with 340 votes in favour in a final ballot on the issue.
The motion to allow congregations to appoint ministers in same-sex relations, with an opt-out option, fell after netting 282 votes.
Equality Network, Scotland's lesbian, gay, bisexual and transgender (LGBT) equality charity, welcomed the move, saying it was a positive step forward towards a more equal society.
Policy co-ordinator Tom French said: "We welcome this decision by the Church of Scotland, which is particularly important for the many LGBT people within the Church and their friends and family. This is a positive step forward for a more equal society, and speaks to the progressive values of 21st century Scotland."
But the Free Church of Scotland branded the outcome of the debate "totally confusing".
A spokesman said: "The winning motion says that it affirms the historic doctrine of the Church, which is of course opposed to the ordination of ministers in same-sex relationships.
"Yet at the same time the motion permits congregations to call ministers in same-sex relationships. The whole thing is totally confusing.
"We don't understand what's going on in the Church of Scotland, and suspect the vast majority of the Scottish public don't have a Scooby either.
"We believe that Scotland needs the guidance of the national church rooted in the teachings of the Bible, irrespective of public opinion and pressure to conform.
"Today's debate simply demonstrates the growing confusion amongst Scotland's national church, at a time when the public are looking to it for direction from the scriptures."
Putting his ultimately successful proposal forward, Mr Bogle apologised for the last-minute nature of his intervention.
He told the Assembly: "I really didn't mean to ever be here today. I apologise that you have got papers that have come very late to you. I apologise too because I never meant to enter into this debate, because I was the moderator until very recently."
Mr Bogle, who said he approached the issue from a traditionalist standpoint, said it seemed there were two "polarised views" on the issue, with no obvious way of moving forward.
He told commissioners: "Please will you hear my plea because I speak for people in this room for whom it is even painful to talk of these things?
"We might be wrong and therefore we need to be gracious and listen to others and be prepared to move a little.
"My motion is that that by seeking to maintain what I believe the Church of Scotland should be ... (we) recognise that there are others who perhaps have greater enlightenment in the power of the spirit and are much braver than I could ever be and say, 'this is the way we should be going'.
"I don't want to be the one who stands and says, 'you must not do this', because I have worked and lived in this Church with many of them for the last X number of years and we have loved one another.
"My motion is to be permissive and to allow those who want to do this to do it. But I want to affirm the position of the Church of Scotland in the historic tradition of the Church."
He added: "I ask that you take that step with me. It will give everyone what they want but it will keep us together. It will not be what everybody desires because we will all in some way be hurting, but we'll have moved a little bit and we'll have confounded the critics that we cannot stay together as God's people."