The Church of Scotland has voted to allow clergy to conduct same-sex marriages for the first time.
Members of the General Assembly in Edinburgh voted to change church law following years of campaigning.
It means same-sex couples will be able to marry in church in services conducted by ministers.
Ministers and deacons will be able to apply to become celebrants of same sex marriage, but they will not be forced to take part.
The results of the vote were: 274 for and 136 against.
Rt Rev Dr Iain Greenshields, moderator of the General Assembly, said: "The Church of Scotland is a broad church and there are diverse views on the subject of same-sex marriage among its members.
"There has been a lengthy, prayerful and in-depth discussion and debate about this topic for many years at all levels of the Church to find a solution that respects diversity and values the beliefs of all.
"The Church is committed to ensuring that debates on this subject are held in a spirit of humility and grace, the tone and tenor of discussions are civil and people are respectful of those who hold opposing views."
'Support the deliverance'
Before Monday's vote, members of the assembly expressed a range of opinions on the change.
Among them was Rev Scott Rennie, who in 2009 became the first openly gay clergyman in the Church of Scotland to have his appointment approved - despite protests by some sections of the Kirk.
He was not able to marry his husband in a religious ceremony, as he would have wanted.
He told the General Assembly: "I sincerely hope the assembly will find it in itself to support the deliverance, even those who have their doubt."
He acknowledged those within the Church who did not support the issue.
He said: "I want to say that marriage is a wonderful thing. My marriage to my husband Dave nurtures my life and my ministry.
"Frankly, I couldn't be a minister without his love and support. It is much the same as opposite sex marriage in its joys and its glories."
Last year, the Methodist Church became the largest religious denomination in the UK to permit same-sex marriages.
It is not allowed in the Church of England or the Roman Catholic Church, but is welcomed in the Scottish Episcopal Church, the United Reformed Church and the Quakers.
Well, I may have gotten in too early, given the debate which is due @churchscotland #GA2022 in Legal Questions on Wednesday, but I've emailed the Principle Clerk's office requesting to be registered to conduct Same sex weddings.#LoveIsLove— Susan Cord 🌻 (@sue_cord) May 23, 2022
Rev Susan Cord announced on social media that she has already applied to become a celebrant of same-sex weddings.
The minister of Killearnan & Knockbain parishes near Inverness told BBC Scotland: "We make a choice based on what the scripture tells us. There will be colleagues who will decide not to conduct these ceremonies and I will respect that.
"But for me it is about choice and if a couple, irrespective of gender, whether it is a man and a man, a woman and a woman or a man and a woman, if they love one another and want to show commitment, I want to help them do that.
"This opens up the choice. People will have held off getting married in civil partnerships because they are Church of Scotland and wanted to wait to be married in their own church."
'Unbiblical and sinful'
The Covenant Fellowship Scotland, a think tank of evangelicals within the Church of Scotland, issued a statement accusing the Church of making a "serious mistake"
It said: "The General Assembly of the Church of Scotland, in converting an overture permitting ministers and deacons to officiate at same-sex marriages into an Act of the Church, has acted in a way which is both unbiblical and sinful.
"We all have a deep pastoral care and concern for those who wish to enter into same sex marriages, and we understand the pastoral impulse of ministers and deacons who wish to help people at life's key moments.
"But we must nevertheless point to the complete absence of any compelling or persuasive biblical evidence that might permit ministers and deacons of the Church of Scotland to officiate at same sex marriages."
It continued: "This decision contradicts everything the Bible has to say about the complementary nature of men and women, and of the character and purposes of marriage.
"Instead of following the clear and unambiguous teaching of God's written word, the Bible, the Church of Scotland continues to follow popular opinion."
Public figures have welcomed the decision, including former Scottish Conservative leader Ruth Davidson, and former Scottish Labour leader Kezia Dugdale, who are both in same-sex relationships.
Baroness Davidson tweeted: "Delighted to see that the General Assembly of the Church of Scotland has voted for ministers to be able to conduct same-sex weddings.
"Thanks to those who have shown grace and care as the church edged closer and closer to this point."
Ms Dugdale described it as "tremendous news and progress".
Same-sex weddings could take place in Church of Scotland buildings later this year.