THE Church of Scotland has voted to allow the appointment of ministers in same-sex relationships in a historic shift, despite a lingering threat of an evangelical split.

Two former moderators to the Church's General Assembly were key to the day-long debate, which was sparked by the appointment of the openly gay Reverend Scott Rennie to Queen's Cross Parish Church in Aberdeen four years ago.

A surprise 11th-hour challenge to the Kirk's own Theological Commission by last year's moderator, the Very Reverend Albert Bogle, led to the groundbreaking decision. The final vote was 340 to 282.

The current Moderator, the Right Reverend Lorna Hood, said: "This is a massive vote for the peace and unity of the Church."

And Mr Rennie welcomed the move last night, saying decision would allow congregations to call the minister of their choice: be they lesbian, gay, bisexual or straight.

But traditionalists warned it could cost the Kirk "members, ministers, congregations and money".

Mr Bogle's motion at the Kirk's annual gathering called for a traditionalist stance, but allowing congregations to opt out. It overturned the commission's revisionist option that would have meant congregations against gay ministers in same-sex relationships would have to opt out.

How it will work is unclear and a new Theological Forum will examine the issue. The process of opting out may involve some form of congregational declaration, one minister suggested.

Such a decision was failure of leadership, according the Reverend David Randall, who said such sitting on the fence would anger many traditionalists who believe Scripture does not sanction homosexuality.

A moratorium on recruitment of gay clergy remains in place until at least next year.

Former moderator the Very Reverend Dr John Cairns introduced a strongly revisionist amendment to allow all gay clergy. He reminded commissioners of Archbishop Desmond Tutu's previous address to the assembly when he said "all belong to the Church".

He withdrew his motion after his speech to the assembly at The Mound in Edinburgh.

Mr Bogle described Mr Cairns as a "clever fox" before laying out his motion. He said he felt compelled to lodge his challenge. He said: "I have put myself out on a limb just has John [Cairns] has, and if I am cut off I am cut off."

Mr Bogle's motion was accepted by some traditionalists. Seconding the move, the Reverend Alan Hamilton of Killermont Parish in Bearsden, East Dunbartonshire, said: "I do not want to depart from the traditional view of the Church, a view I believe is enshrined in the Bible and the will of God.

"But I believe this is the time for the Church, particularly traditionalists like me, to concede to allow others who disagree space to express that disagreement."

He described it as an option that "does not require the Church to abandon its traditional position and all that flows from it, not least our position among world churches".

However, Mr Randall said the issue of gay clergy "has been forced upon us by the revisionists who want us to turn our backs on what common sense tells us".

"If we go revisionist or try to sit on the fence then we will lose members, ministers, congregations and money. Are we to stand by Scripture or are we to go with the flow of social trends?"

The Reverend John Chalmers, Principal Clerk of the Kirk, said: "This has been a massive vote for the peace and unity of the Church. At the end of a long day we came down to a choice of two motions, both of which were for what we have called from the beginning: the mixed economy."

Tom French, policy co-ordinator for the lesbian, gay, bisexual and transgender (LGBT) campaign group, Equality Network, 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."

The decision will go back to General Assembly next year for the law to be drafted and fully introduced in 2015.

The appointment of Mr Rennie, who was backed by most of his congregation and by the General Assembly, in 2009 caused two congregations and six ministers to break away.