The Scottish Episcopal Church (SEC) has taken the "momentous" decision 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.
The "historic" move - making it the first branch of the Anglican faith in the UK to allow same-sex marriage - has been welcomed by equal rights campaigners.
However, it puts the Church "at odds" with the majority stance within the Anglican communion and raises the question of whether it could face sanctions as a result.
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 clause which asserts that clergy who do not wish to preside over same-sex weddings will not be compelled to do so "against their conscience".
The proposal was passed with 80% support from the houses of Bishops and Laity, while 67% of the Clergy backed the move - achieving the required two-thirds majority overall.
Same-sex weddings could be held within the church by the autumn, reports have suggested.
Speaking after the vote, Primus of the SEC, the Most Rev David Chillingworth, 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."
He acknowledged the decision will be difficult for some and added: "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.
The Secretary General of the Anglican Communion said the SEC's decision puts it "at odds with the majority stance that marriage is the lifelong union of a man and a woman".
Archbishop Josiah Idowu-Fearon said: "This is a departure from the faith and teaching upheld by the overwhelming majority of Anglican provinces on the doctrine of marriage."
He went on: "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 the issue of same-sex marriage "is something on which we do not have a common mind", b ut he stressed "no-one is being asked to change their theology of marriage".
However, another speaker told the gathering: "This is one of the saddest and most painful days for many of us ... we are broken.
"Changing our doctrine of marriage 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.
But in February 2017, 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''.
The Church of England said the latest decision was a matter for the SEC.
A spokesman said: "The Church of England is unable by law to marry couples of the same sex and the teaching of the Church of England remains unchanged.
"However this is a matter on which there is real and profound disagreement in the Church of England."
Professor Paul Johnson, of the University of York's Department of Sociology, said the decision of the SEC is one of "great significance".
He said: "Not only is it now at odds with its close neighbours, the Church of England and the Church in Wales - that remain opposed to same-sex marriage - but its approach is in contradiction with those other provinces and churches that, together with the Scottish Episcopal Church, make up the 80 million strong membership of the worldwide Anglican Communion.
"The Scottish Episcopal Church could face 'sanctions' by the Anglican Communion for its decision.
"When the Episcopal Church in the United States took the same decision it was effectively excluded by the Primates of the Anglican Communion from participating in the business of the Communion for a period of three years.
"In ending one of the most odious forms of discrimination against gay people, the Scottish Episcopal Church has made the full and frank statement that same-sex relationships are of equal worth to opposite-sex relationships.
"That statement will reverberate in the Anglican Communion and hopefully encourage other member churches, including the Church of England, to take the same decision."
Copyright (c) Press Association Ltd. 2017, All Rights Reserved.