The Scottish Episcopal Church (SEC) has voted to allow same-sex couples to be married in church.
A proposal to amend canon law to permit clerics to conduct weddings for gay couples was backed on Thursday at the annual meeting of the church's General Synod in Edinburgh.
Under the terms of the vote, clergy who do not wish to preside over same-sex weddings will not be compelled to do so "against their conscience".
The historic decision makes the SEC the first branch of the Anglican faith in the UK to allow same-sex marriage.
Equal-rights campaigners were quick to welcome the decision.
However, the Secretary General of the Anglican Communion, Archbishop Josiah Idowu-Fearon, said the vote puts the Scottish Episcopal Church at odds with the majority stance within the Anglican Communion.
In approving the proposal, church members voted to remove the doctrinal clause which stated that marriage is a "union of one man and one woman".
It was replaced with a "conscience clause" which states: "In the light of the fact that there are differing understandings of the nature of marriage in this church, no cleric of this church shall be obliged to conduct any marriage against their conscience."
A two-thirds majority was required in each house of Bishops, Clergy and Laity for the measure to be accepted.
The proposal was passed with 80% support from the Bishops and Laity, while 67% of the Clergy backed the move.
A first reading of the motion to amend Canon 31 was passed by the General Synod in 2016 and it returned for its second and final reading this year.
Same-sex weddings could be held within the church by the autumn of this year, reports have suggested.
Responding to the vote, Primus of the SEC, the Most Rev David Chillingworth, Bishop of St Andrews, Dunkeld and Dunblane, said: "This is a momentous step.
"By removing gender from our marriage canon, our church now affirms that a same-sex couple are not just married but are married in the sight of God. They can 'leave and cleave'.
"They can express in marriage a commitment to lifelong faithfulness to one another and to the belief that a calling to marriage is for them too a calling to love, forgiveness, sacrifice, truth.
"A new chapter opens up - inclusion has taken a particular form.
"This same decision is difficult and hurtful for others whose integrity in faith tells them that this decision is unscriptural and profoundly wrong.
"For them, this new chapter will feel like an exclusion - as if their church has moved away from them.
"So, the journey which we now begin must also be a journey of reconciliation."
Colin Macfarlane, director of gay-rights charity Stonewall Scotland, voiced delight at the change.
"This step allows couples to celebrate their love within their faith and sends a really positive message to other LGBT (lesbian, gay, bisexual, and transgender) people, both here and around the world," he said.
"It signals that members of the church welcome, recognise and respect LGBT people as part of the faith community."
Archbishop Idowu-Fearon said the churches of the Anglican Communion are free to make their own decisions on canon law, with the SEC being one of 38 provinces covering more than 165 countries around the world.
He added: "Today's decision by the SEC to approve changes to canon law on marriage is not a surprise, given the outcome of the vote at its Synod a year ago.
"There are differing views about same-sex marriage within the Anglican Communion but this puts the Scottish Episcopal Church at odds with the majority stance that marriage is the lifelong union of a man and a woman.
"This is a departure from the faith and teaching upheld by the overwhelming majority of Anglican provinces on the doctrine of marriage.
"The Anglican Communion's position on human sexuality is set out very clearly in Resolution 1.10 agreed at the Lambeth conference of 1998 and will remain so unless it is revoked.
"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."
During an earlier debate on the issue on Thursday, the Rt Rev John Armes, Bishop of Edinburgh, said: "Clearly, the issue of the marriage of same-sex couples is something on which we do not have a common mind.
"The new Canon ... will protect the consciences both of those who believe that they must not and of those who believe that they must offer God's blessing on a marriage of a same-sex couple.
"No-one is being asked to change their theology of marriage. The change is that our church would officially recognise that it contains a diversity of viewpoints."
However, another speaker told the gathering: "This is one of the saddest and most painful days for many of us, both here and throughout the Scottish Episcopal Church.
"We are broken and we need to acknowledge that."
He went on: "Changing our doctrine of marriage, which this revisionist Canon does, is a schismatic move that will cause serious harm to our unity and future relationship with our sisters and brothers throughout the Anglican Communion."
Same-sex marriage became law in Scotland in 2014.
In January last year the American branch of the Anglican Communion was sanctioned over its views on marriage and homosexuality.
A meeting of Anglican primates in Canterbury reached an agreement on measures against the US Episcopal Church, which a statement said had made a "fundamental departure from the faith and teaching" by endorsing gay marriage.
In February this year, campaigners hailed a decision by the Church of England's ruling body to throw out a controversial report on same-sex marriage as ''a victory for love and equality''.
Last month, the General Assembly of the Church of Scotland moved a step closer to allowing ministers to perform gay marriages when the Kirk's governing body backed calls for a study into how same-sex ceremonies in church could be allowed.