The Church of Scotland 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 a 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 must 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 chose 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."