The Scottish Episcopal Church has voted to allow gay couples to marry in church.
It makes it the first major Christian church in the UK to allow same-sex marriages.
The vote to amend canon law on marriage, removing the stipulation that it is between a man and a woman, was carried by the Synod in Edinburgh.
It means that gay Christians from any Anglican Church can now ask to be married in a Scottish Episcopal Church.
Clergy who wish to officiate at gay marriages will have to "opt-in".
The church said this meant that those who disagreed with gay marriage would be protected and not have to act against their conscience.
The Episcopal Church's Bishop of Edinburgh, The Right Reverend Dr John Armes, said: "I am very pleased for the couples who can now have their relationships recognised by the church and blessed by God.
"I'm also pleased for what this means about our church and the way we have been able to do this. But obviously any change like this creates pain and hurt in some as well, so as a bishop of the church I feel for them."
The vote to allow same-sex marriage - which required the backing of at least two thirds of each house of Bishops, Clergy and Laity - has left the church at odds with most of the rest of the worldwide Anglican Communion.
A group of global Anglican traditionalists have now announced that they will appoint a missionary bishop "to serve the needs of those who oppose gay marriage".
A senior figure in the group, Archbishop Foley Beach, said: "Today's decision by the Scottish Episcopal Church to change the biblical and historic definition of marriage has highlighted the need to respond to the cries and pleas of those Scots who today have been marginalised by their leaders.
"The attempt to redefine marriage is not one that a faithful Christian can support."
At last year's Synod, members of the Church agreed to send the issue for discussion to its seven dioceses.
Six of them voted in favour of amending the law. Only Aberdeen and Orkney voted against the proposal.
Analysis by BBC Scotland correspondent John McManus
This vote to change canon law, opening marriage to same sex couples, isn't just the latest skirmish in the religious war between traditionalist Christians and those of a more liberal leaning.
It will have profound consequences, because the issue of gay relationships has become a touchstone for those who believe that the Anglican Church has lost its way, and needs to be renewed.
Many Christians who live in the global south, where the 80-plus million Anglican Communion is at its strongest, look with horror at what they see as moves to legitimise gay relationships and lifestyles.
'Ignoring the will of God'
They not only disapprove of those lifestyles, but they see moves such as the ordination of gay clergy as evidence that the church is ignoring the will of God.
The head of the Anglican Communion is the Archbishop of Canterbury and he's come under enormous pressure from bishops in Africa and Asia to stand firm on this issue.
Those bishops are growing in influence and have formed an organisation - Gafcon - which is directly challenging the more liberal Christians of the global north.
They will be emboldened by this vote, even if they disapprove of it - and it may hasten a split in the communion, with power moving south to the churches of Africa.
Same sex marriage became legal in Scotland at the end of 2014 but the Church of Scotland and the Roman Catholic Church opposed the move.
The issue has provoked passionate debate within the Anglican Communion.
In January last year, the communion sanctioned the US Episcopal Church when it decided to allow gay marriage in church.
However, last month the Church of Scotland voted to approve a report which could allow ministers to conduct same-sex weddings in the future.
And in February, a report opposing gay marriage was opposed by the Church of England's Synod.
'Departure from faith'
The Secretary General of the Anglican Communion described the Episcopal Church's decision as "a departure from the faith and teaching upheld by the overwhelming majority of Anglican provinces on the doctrine of marriage".
Archbishop Josiah Idowu-Fearon said: "The churches of the Anglican Communion are autonomous and free to make their own decisions on canon law. The Scottish Episcopal Church is one of 38, soon to be 39, provinces covering more than 165 countries around the world.
"As Secretary General, I want the churches within the Anglican Communion to remain committed to walking together in the love of Christ and to working out how we can maintain our unity and uphold the value of every individual in spite of deeply-held differences. It is important to stress the Communion's strong opposition to the criminalisation of LGBTIQ+ people.
"The primates of the Communion will be meeting in Canterbury in October. I am sure today's decision will be among the topics which will be prayerfully discussed. There will be no formal response to the SEC's vote until the primates have met."
'Really positive message'
The equality campaign group Stonewall Scotland said it was "delighted" with the outcome of the vote.
The groups's director Colin Macfarlane said: "This step allows couples to celebrate their love within their faith and sends a really positive message to other LGBT people, both here and around the world.
"It signals that members of the church welcome, recognise and respect LGBT people as part of the faith community."
The Student Christian Movement UK said: "We hope this is a watershed for LGBT inclusion in UK churches.
"Our prayers go out to all LGBT Christians who have been hurt by the Episcopal Church, and we hope this may be a turning point for healing and reconciliation."