The General Assembly of the Church of Scotland has voted to allow congregations to ordain gay ministers who are in same sex civil partnerships.
Delegates voted 309 in favour and 183 against.
The vote followed a church-wide debate and consultations with all 45 presbyteries, which voted 31 to 14 in favour of change.
A further vote will be held this week on whether or not to extend ordination to ministers in same sex marriages.
Supporters said it was time for the church to be inclusive and recognise the "mixed economy" of modern Scotland.
Opponents warned that the move was contrary to God's law, would prove divisive and lead to resignations.
A spokesman for the Church of Scotland said that the current stance meant that the Church had adopted a position which "maintains a traditional view of marriage between a man and woman, but allows individual congregations to 'opt out' if they wish to appoint a minister or a deacon in a same sex civil partnership."
No Kirk session can be forced into doing so.
The debate predates the legalisation of gay marriage, so the Assembly will be asked next Thursday to consider amending the new Kirk law to include ministers in same-sex marriages.
The ordaining of gay ministers has proved a controversial topic for years.
In 2009 some members attempted to block the appointment of the Reverend Scott Rennie, who is gay, to Queen's Cross Church in Aberdeen.
At the Kirk's gathering in 2011, commissioners voted to accept gay and lesbian clergy - on the condition they had declared their sexuality and were ordained before 2009.
The Kirk then prepared a report by its theological commission, which set out arguments on both sides.
Last year, the general assembly voted to allow presbyteries to debate whether congregations could opt out of its traditional stance and appoint homosexual ministers.
They also agreed to put new draft legislation out to local presbyteries to settle the issue once and for all.
The presbyteries came back in favour of change by 31 to 14.
At the opening of the General Assembly, which was attended by First Minister Nicola Sturgeon, Rev Dr Angus Morrison was installed as the new Moderator.
He was forced to withdraw from the role last year to undergo treatment for cancer.
In a speech later on Saturday, the outgoing Moderator Very Rev John Chalmers was to say: "We cannot go on suffering the pain of internal attacks which are designed to undermine the work or the place of others. It's time to play for the team.
"And let me be very clear here - I am not speaking to one side or another of the theological spectrum. I am speaking to both ends and middle.
"It is time to stop calling each other names, time to shun the idea that we should define ourselves by our differences and instead define ourselves by what we hold in common - our baptism into Christ, our dependence on God's grace, our will to serve the poor and so on."