Gay marriages may soon be able to take place in the Church of Scotland.
A report to be debated at the Kirk's General Assembly in May said ministers should be permitted to perform same-sex ceremonies.
It also said the Kirk should apologise for failing to recognise the Christian vocation of gay people.
The report has been welcomed by the Reverend Scott Rennie, the gay minister whose appointment to an Aberdeen parish in 2008 caused controversy.
It will be presented to the General Assembly by the influential Theological Forum of the Church of Scotland, which challenges and expresses the theology of the life and work of the Kirk.
The Church of Scotland's principal clerk authorised early publication of the report following media coverage.
The General Assembly is being asked to consider:
- Authorising the Legal Questions Committee to undertake a further study on the legal implications of conducting same-sex marriages and report back in 2018
- Inviting the Church to take stock of its history of discrimination at different levels and in different ways against gay people and to apologise individually and corporately and seek to do better.
The report stated: "We recognise that as a Church we have often failed to recognise and protect the identity and Christian vocation of gay people and believe that the Church as a whole should acknowledge its faults, whose identity and Christian vocation it has failed to recognise and protect."
Mr Rennie said the report was far-reaching, thorough, and impressive.
He said: "The request that the Kirk recognise its damaging failure through the years to value, encourage, and support gay people in its pews - and to do better in the future - is one of the most positive and hopeful things I have read in a report to the General Assembly in many years.
"It recognises, at last, the diversity of people that make up the Church of Scotland, and Scotland at large.
"It says in its own theological language: you are valued; you are part of us; and we have to do better at including you - and being just in our treatment of you."
The report reflected a range of theological thinking on the issue of same-sex relationships.
It acknowledged the traditionalist view that Biblical writers condemned same-sex acts, making the only appropriate response for the Church was to proclaim they are contrary to God's intentions for humanity - meaning gay marriages should be prohibited.
But it also examined the revisionist arguments.
It said: "Scriptural condemnations of same-sex sexual activity were framed in cultural contexts very different from our own and referred to individual acts rather than committed and faithful people willing to enshrine their relationships in vows before God."
The principal clerk to the General Assembly, the Very Reverend John Chalmers, said the issue had been a long-running argument in which there would not be a sole victor.
He said the Kirk called it "constrained difference", meaning that within limits it can make space for more than one approach among ministers and congregations.
He said: "When mutual flourishing is what you aim for, then you try to heal where you can.
"In an argument over 20 years, some people have been hurt on both sides. Some have felt unheard, marginalised and denied.
"That is why we think the recognition that some apologies all round are needed may help promote reconciliation and help us live with our differences where they exist."
Commenting on the early publication of the report, he added: "It is unfortunate that this report has found its way into the public domain before this year's volume of Assembly Reports has been published.
"However, it is important that people are now able to access the full report."
The Reverend Mike Goss, parish minister of Barry with Carnoustie Church, told BBC Scotland he did not think it was right that ministers should be allowed to perform same-sex ceremonies.
"Same-sex relationships are not what God has planned for us as human beings," he said.
"We are all messed up in different ways in our lives. I don't see that people in straight-sex relationships have got it all sorted. We know too many of them have gone wrong as well.
"But we don't bless that which is wrong and that has got to be key in terms of the Gospel."
Mr Rennie added: "Loving marriages, whether they are gay or straight, can make for a good and happy life.
"Christ's love for us, his people, is reflected in loving relationships. Marriage is something to be celebrated.
"I look forward to the day when I am able to conduct weddings for all couples, gay or straight, in the name of God."
The General Assembly will be asked to accept the report - but gay marriages in the Church of Scotland may not happen quickly.
The Kirk is keen to ensure it will not lose its current protection under equalities laws, and that those ministers or deacons who decline to carry out same-sex services cannot be prosecuted.
The Roman Catholic Church opposes same-sex marriage, while Scottish Episcopalians will make a decision in June - potentially putting them at odds with the Church of England.
Legislation allowing same-sex marriage in Scotland was passed by MSPs at Holyrood in February 2014 and came into effect in December that year.
A Scottish government spokeswoman said: "Decisions on whether or not to take part in same-sex marriage are a matter for individual denominations.
"The legislation was framed to reflect that some religious bodies would wish to take part and others would not, and within those religious bodies choosing to take part, some of their celebrants would not wish to do so."