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: 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 kirk 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".
The 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."