Image caption The appointment of the Reverend Scott Rennie divided the church

The Church of Scotland has voted to allow the possible selection of gay and lesbian ministers in the future.

The controversial issue was being debated at the Kirk's General Assembly.

A theological commission will now be set up and will report in 2013 before a final decision on the issue of gay ordination is taken.

Earlier the Assembly voted to accept gay and lesbian clergy provided they had declared their sexuality and were ordained before 2009.

Two years ago, the Reverend Scott Rennie's appointment to Queen's Cross Church in Aberdeen threatened to split the Church.

At the General Assembly, commissioners were being asked whether to continue an indefinite ban on the ordination of gay ministers until a report next year or lift the ban and await a separate report which would be published in two years.

One in five members of Kirk sessions have said they would leave if it was agreed that gay ministers can be ordained, while one in 10 have said they would leave if the Kirk ruled they could not be ordained.

Stonewall Scotland welcomed the General Assembly's decision to allow gay and lesbian ministers.

Carl Watt, director of the charity, said: "We hope today's decision signals the start of the Kirk demonstrating a commitment to fairness, equality and dignity on this issue.

"Our research has shown that people of faith are no more likely to be prejudiced towards gay people and same-sex relationships than anyone else.

"Reverend Scott Rennie was inducted as the first openly gay minister in the Church of Scotland two years ago in the face of strong opposition from some quarters - yet supported by his own Aberdeen congregation.

He added: "Although we await further decisions from the assembly and details on the next steps, we hope that in 30 years' time this will be regarded as a storm in a teacup."

The subject of gay ministers hit the headlines two years ago as traditionalist members attempted to block Mr Rennie's appointment.

Following a lengthy debate, the Assembly ultimately voted in support of the Aberdeen-based minister but called for a commission to study the general issue "for the sake of the peace and unity of the church".