General assembly votes to allow congregations to admit gay ministers but only if they specifically elect to do so

The Church of Scotland, the country's largest Protestant church, has narrowly voted to admit gay and lesbian ministers after traditionalists agreed to compromise after four years of division.

The church's ruling general assembly voted to allow congregations to admit gay ministers but only if they specifically elect to do so, in a radical departure from more than 450 years of orthodoxy set in train by the protestant reformer John Knox.

The vote is likely to lead to an end to a four-year controversy which has split the church after an openly gay minister, Scott Rennie, was selected to lead Queen's Cross parish in Aberdeen in 2009.

The general assembly, equivalent to the Church of England's synod, rejected a motion which would have made gay ordination – solely for ministers in civil partnerships or who are celibate - the default position of the Church of Scotland, by 340 votes to 282.

The new deal – which now has to be written into a new church law and authorised by next year's general assembly - affirms the traditional teaching of the church as favouring heterosexual ministers, but will allow congregations to opt in to select gay ministers if they wish.

The church's complicated law-making procedures could still mean the compromise measure – which was proposed in a late motion tabled on Monday by the previous moderator, Albert Bogle, may not be law until 2015.

John Chalmers, the Church of Scotland's principal clerk, said the vote was historic: "This has been one way or another, a massive vote for the peace and unity of the church." He said both sides of the debate had moved to agree a compromise.

The general assembly had voted for the "mixed economy", he said, where congregations could decide to uphold traditional teachings to only employ heterosexual ministers but whether others could take on gay and lesbian ministers.

Critics of gay ordination had warned that scores of Church of Scotland ministers and congregations could leave in protest at proposals to make it church policy that all congregations had to accept gay ministers unless they opted out of doing so.

Six ministers and two congregations have already resigned, while senior figures in the far more orthodox Free Church of Scotland said that around 50 ministers have been in touch about defecting.

The Church of Scotland has been edging towards gay ordination ever since Rennie's appointment: in 2011, the general assembly voted to allow gay ministers already in post to remain in place, so long as they were in openly-declared civil partnerships or celibate, and had been ordained before 2009.

The vote came after the general assembly heard from the Rev Elizabeth Spence, a lesbian minister from Ibrox in Glasgow.

"For me, there is nothing bigger than whether I'm accepted in this church or not, because I am a gay woman," she said, adding: "It's now time; it's time to decide, so those of who are in this limbo can get under the wire."

A minister based in England, the Rev Jim Sharp, also urged the assembly to support gay ordination, in the spirit of accepting the total equality of all people, regardless of gender, ethnicity or sexuality.

"Let us be brave, let us bold," he said. "Let us not put ourselves in the position where ten, 20 years from now, people say of us 'how on earth can anyone think that lesbians and gays were second class citizens and not worthy to be treated as equals?'"

The Rt Rev Roy Patton, the moderator of the Presbyterian Church of Ireland, warned the delegates there would be serious tensions within the global presbyterian church if the general assembly voted to admit gay ministers. That would be "hard to comprehend", he said.

"It would lead a church away from the tradition of the church," he said. "We do believe this is contrary to the message of god and will make it difficult for the church as a whole to reach out to the wider world."

The Rev David Randall, another traditionalist, said the controversy had already divided the church: it had lost ministers, congregations and money as a result. There were other people in the church "hanging on by the fingernails", hoping the move towards gay ordination would be blocked.

The proposals in the church's theological commission report on ordaining gay ministers for a gay marriage liturgy was one of his "worst nightmares", Randall said. "The basic issue is whether or not this church stands by the teaching of scripture or whether we think that we know better than god's will," he said. "This is no time for compromise."