The Scottish government has published its proposed legislation to introduce gay marriage.

Ministers, who previously decided they want to make the change, are now asking for people's views on a draft bill to be put to the Scottish Parliament.

Under the plans, religious and belief bodies would need to "opt in" to perform same-sex marriages.

Both the Church of Scotland and Roman Catholic Church are opposed to the proposals.

Scottish ministers have insisted no part of the religious community would be forced to hold same-sex weddings in churches.

The SNP is concerned to avoid any prospect of a political backlash - particularly with an eye upon a particular test of popular opinion in 2014.

By Brian TaylorPolitical editor, Scotland

The Scottish government also said it would work with UK ministers to amend equality laws, to protect celebrants from legal or disciplinary action if they refuse to take part or speak out against same-sex ceremonies.

The move came after the UK government announced plans for gay marriage in England and Wales.

The Church of England and Church in Wales will be banned in law from offering same-sex marriages, with other religious organisations able to opt in to holding ceremonies.

Provision making it clear that the introduction of same-sex marriage has no impact on existing rights to freedom of speech and that it is possible oppose to same-sex marriage "without being homophobic"

Amended guidance on the teaching of the issue in schools

An intention to recognise same-sex marriages registered elsewhere in the UK and overseas.

Rev Alan Hamilton, convener of the Church of Scotland's legal questions committee, said that, unless the organisation's General Assembly decided otherwise, it would oppose same-sex marriage.

He added: "We have also expressed concerns about the speed with which the government is proceeding with this and what we fear will be inadequate safeguards for religious bodies and ministers and people of faith who view this as being contrary to their beliefs."

Archbishop Philip Tartaglia said the legislation needed more safeguards, adding: "The Catholic Church has made its view very clear that the redefinition of marriage is unwise and unnecessary."

Gay rights organisations, including the Equality Network and Stonewall Scotland, and a range of other groups, welcomed the government move.

Announcing the consultation, Mr Neil said: "We are striving to create a Scotland that is free, tolerant and fair and I am pleased to say there is support across the chamber for this significant step."

'Natural step'

Willie Rennie, the Scottish Liberal Democrat leader, added: "Equal marriage is the right and natural step towards the modern, tolerant and progressive Scotland we all want to see."

The Greens' Patrick Harvie said his party had supported equal marriage for more than a decade, adding: "Wider Scottish public and political opinions have been moving in the direction of equality for many years too, and I congratulate the Scottish government for taking this next logical step."

Independent MSP Margo MacDonald said of the consultation: "The more people who discuss the question, the harder it will be for anyone to recommend that such an inequality of treatment should be tolerated."

Scottish Labour leader Johann Lamont added: "Equality for LGBT people in the UK has always been advanced by the Labour Party, from equalising the age of consent, introducing anti-discriminatory policies, introducing civil partnerships and promoting equality across Europe and beyond."

And the Tories' Ruth Davidson said: "I support the principle of equal marriage, but with the important proviso that religious organisations which do not wish to carry out the ceremony are not compelled to do so.

"I will be examining the bill closely to ensure such religious protections are in place."

The draft bill came following a previous Scottish government consultation on the issue, which produced a record 77,508 responses.

Same-sex couples in Scotland currently have the option to enter into civil partnerships, and there has been an indication that the earliest gay marriage ceremonies could take place by the start of 2015.