Legislation to allow same sex couples to get married has been published.

The Scottish Government has brought forward proposals at the same time as ministers launched a review of whether civil partnerships, currently only available to gay couples, should be opened up to mixed sex couples.

Health Secretary Alex Neil said the publication of the same sex marriage legislation marked "an historic moment for Scotland and for equal rights in our country".

The Scottish Government proposals also aim to protect the rights of religious celebrants and groups who are opposed to allowing gay couples to wed.

Under the plans religious bodies would have to opt in to perform same sex marriage ceremonies. If a religious group does decide do this, protection will also be offered to individual celebrants who feel it would go against their faith to carry out gay weddings.

"We are striving to create a Scotland that is fairer and more tolerant, where everyone is treated equally. That is why we believe that same sex couples should be allowed to marry," Mr Neil said.

"A marriage is about love, not gender. And that is the guiding principle at the heart of this Bill.

"At the same time, we also want to protect freedom of speech and religion, and that's what the Bill sets out to do. That is why it will be up to the religious body or individual celebrant to decide if they want to perform same sex marriages and there will be no obligation to opt in."

As well as publishing the Marriage and Civil Partnership (Scotland) Bill, Mr Neil said the Scottish Government published details of an agreement with the UK Government on changes to be made to the Equality Act to protect individual celebrants who may not want to conduct same-sex ceremonies even if their church, as an organisation, backs them.

Mr Neil told BBC Radio Scotland this would "give unequivocal protection in terms of making it illegal to discriminate against anyone who refuses to participate in a same-sex marriage ceremony".

At the same time, the Crown Office has published new advice making clear that criticism of same-sex marriage is not an offence.

Work will take place with the education sector to update guidance on sexual health education - but this will continue to make clear that parents can remove their children from such lessons.

Mr Neil told the Good Morning Scotland programme: "I think we've got the best package today, not just in terms of the Bill but in terms of the Lord Advocate's statement on prosecutorial guidelines, the timetable for consultation on educational guidelines, the review on opposite-sex civil partnerships and the amendments to the Equality Act."

Plans to introduce same-sex marriage have already won the backing of the leaders of all the main political parties north of the border.

But they have been fiercely opposed by a number of religious groups, with the campaign group Scotland for Marriage now vowing to step up its efforts to try to halt the legislation.

Mr Neil conceded the proposals were "controversial" but said ministers had consulted "very, very widely" on the plans.

He said: "We actually consulted on the draft Bill, which is not usual, but because it was so controversial and because we needed to allay the fears of people about the implications of this legislation, we felt it was worthwhile taking much more time than normal to consult widely."

If the Bill is passed early next year, it is expected the first gay weddings in Scotland could take place in 2015.

"In terms of the timing of the first same-sex marriages, I would anticipate the timescale for that would be very similar both north and south of the border," Mr Neil said.

"What this is about is extending freedom. We actually have some religious bodies, such as the Quakers, who at the moment want to solemnise same-sex marriages but don't have the right to do so.

"What we're doing is we're extending the right to allow, for example, the Quakers and others who want to do so to solemnise same-sex marriage.

"But at the same time we are protecting the rights of people who do not want to participate in same-sex marriage, they don't want their church to participate in same sex marriage and they will not be forced to participate in same sex marriage."

The publication of the Bill was welcomed by gay rights campaigners.

The Equality Network has been campaigning for same-sex marriage and mixed-sex civil partnerships since 2008.

Policy coordinator Tom French said: "After many years of campaigning for equal marriage we are delighted that the bill has today started its journey into law.

"We hope that our MSPs will stand by the values of equality and social justice that the Scottish Parliament was founded on and vote to pass this bill with the strong majority it deserves.

"Thirty-three years ago Scotland finally decriminalised homosexuality, today the large majority of Scots agree that it's time LGBT people were granted full equality under the law.

"By passing equal marriage legislation our MSPs will not only be giving same-sex couples an equal right to celebrate their love through marriage, they will also be sending out a message to the world about the kind of fair and progressive country Scotland wants to be."

Meanwhile Colin Macfarlane, director of Stonewall Scotland, said: "Many thousands of lesbian, gay, bisexual and transgender Scots, their friends and their families will be delighted that the Scottish Government has finally introduced its Bill.

"The Scottish Parliament can now get on with making marriage equality in Scotland a reality. We know that the thousands of individual supporters who make Stonewall Scotland's campaigning possible will now be looking to their MSPs to show their commitment to equality by voting for equal marriage."

Gay MSP Marco Biagi also welcomed the Bill, stating: "Marriage is a recognition of love and commitment between two people. Whatever their gender, they deserve equality before the law."

The Nationalist, who is the deputy convener of Holyrood's Equal Opportunities Committee, added: "It's now down to us as MSPs to ensure the Bill successfully does what it says on the tin.

"The Bill needs to maintain the freedom of religion for faiths who disagree, while also granting religious freedom for the first time to those faiths - like the Quakers - who have long wanted to perform same-sex ceremonies and have been forbidden from doing so."

However another Nationalist MSP John Mason said it was "highly unlikely" he would vote for the Bill, adding he was unsure if protections promised by the Government could be guaranteed.

Mr Mason, who also sits on the Equal Opportunities Committee said: "It's pretty clear from the parliamentary arithmetic that this Bill is likely to pass.

"However, it is highly unlikely I will vote for the Bill."

Mr Mason said "depending on the evidence" given to MSPs he would either abstain in the vote or vote against the legislation.

"A lot of this will hinge on the legal protections that can be given to those in positions like ministers or priests as well as to public and private sector employees, the third sector, and even volunteers," he said.

"I am still not sure whether, despite the assurances we have been given, these protections can be guaranteed. I don't think any government would want to see ministers or priests dragged through the courts for upholding their personal beliefs in accordance with their faith and so, throughout the scrutiny of this bill, I will be seeking maximum reassurance on this point."

A spokesman for the Free Church of Scotland hit out the Bill.

"This is another step in the destruction of marriage as well as parenthood, and the Scottish Government is essentially legitimising and encouraging the existence of fatherless or motherless children," he said

"The politicians and celebrities are leading us down an irrational and immoral road, the consequences of which they do not yet know."

Rev David Robertson, Free Church minister in Dundee and director of the Solas Centre for Public Christianity, called on MSPs to "swim against the tide of elitist dogma and opinion and actually stand up for the interests of their constituents" on the issue.

"The Scottish Government is rushing into a major social change without thinking through the consequences," he said

"As Alex Neil admitted to me in the Scottish Parliament, this is not a top ten issue for the man in the street, so why is the Scottish Government so determined to push it through?"

A spokesman for Scotland for Marriage also spoke out against the legislation, claiming: "The whole affair is an onslaught against the family, and the SNP is riding roughshod over the views of the majority of ordinary people.

"They are guilty of pursuing dogma at the expense of debate."

He added: "It is clear to ordinary people that you can defend traditional marriage without being guilty of homophobia."

The spokesman claimed Scotland for Marriage had almost 50,000 supporters - adding this was more than the combined membership of the mainstream political parties.

"In coming months we will tell voters the facts, including what redefining marriage means for people's jobs, lives, and families," he said

"Teachers, parents, school kids, foster carers, NHS chaplains and others in everyday life must not be penalised for backing traditional marriage.

"We have warned for more than a year that safeguards and law changes are required but our views have been ignored."

The Scottish Government promised to protect free speech and other civil liberties, including in schools.

He pledged Scotland for Marriage would "up the pace and breadth of our campaign", adding: "We now have activists present in every one of the 73 Holyrood constituencies throughout the country and we will actively target individual MSPs using local voters to urge them to vote against changes in the law.

"A huge national mail drop campaign is already under way with almost 500,000 pieces of literature delivered.

"We will take our fight to the ordinary people of Scotland in cities, towns and villages across the country.

"MSPs will be reminded in no uncertain terms the implications they face if they vote against the views of the majority."