It will go down as one of the most bitter and hard-fought battles ever fought within the Church of Scotland.

At the end of the day, on the thorny issue of the ordination of openly gay clergy, neither side can be said to have "won" or "lost".

Instead, faced with the very real prospect that the Kirk would tear itself apart on the issue, the church's General Assembly commissioners of elders and ministers last night voted for a compromise that, while not fully resolving the issue, sanctions an approach that accommodates both sides of the debate within the Kirk's legal framework.

The ban on gay people in relationships – the traditionalist stance – remains the default position but a conscience clause will allow congregations to appoint such a minister if they wish to. This will regularise the situation created in 2009 when Scott Rennie was appointed the minister of Queen's Cross Parish Church, Aberdeen, by that congregation.

To many outside the church, this may look like a clumsy compromise and some on both sides of the argument will be unhappy with it. Yet it fits well with the Kirk's democratic structure, in which congregations vote to approve a minister selected by a democratically elected vacancy committee.

Even if a majority had voted yesterday to treat gay clergy in civil partnerships as if they were married heterosexuals – the revisionist stance – many congregations would not be considering such a candidate for their pulpit any time soon. Nearly half a century after the Church of Scotland voted to ordain women ministers, some congregations have never considered appointing one. Though most congregations now include female elders, even that was once considered taboo.

This debate is perhaps as much about a generational gap as a theological argument. As in the controversy south of the Border about same-sex marriage, the subject seems to touch a raw nerve with a certain section of society. They are predominantly older people with traditionalist views who grew up at a time when homosexual acts were illegal. Like Church of Scotland congregations, local Conservative associations tend to be dominated by the over-50s.

Younger people, including Christians, are generally more accepting of same-sex relationships. Trading Bible quotations has not taken the debate forward because this is not a black-and-white issue and many believe that, like obsolete rules about dress codes or forbidden foods, the few Biblical references to same-sex relationships need to be seen in their cultural context.

It is difficult to see how, after last night's vote, ministers and congregations can justify joining those who have chosen to leave. It is their choice but it would be a pity. The Church of Scotland is better placed to play a positive role in society if it is a broad church, capable of selecting ministers on the basis of their character and commitment, not on their gender or sexuality. This is a step forward. This issue has dominated the Kirk's agenda for too long. It is time to move on.