Image copyright PA Image caption The law was intended to discourage overtly sectarian behaviour in and around Scottish football matches

MSPs have voted to urge the Scottish government to repeal its Offensive Behaviour at Football Act.

Opposition parties all back scrapping the act, and united to hand the government a symbolic defeat.

Labour's James Kelly has lodged a member's bill aiming to repeal the legislation, and the Tories put the matter forward for debate.

SNP MSPs defended the legislation, saying opponents have not put forward any viable alternatives.

The Offensive Behaviour at Football Act (OBFA) became law in 2012, carried by the votes of the SNP majority government of the time despite opposition from all other parties.

With the SNP now a minority administration, it has come under pressure from opposition groups who maintain that the law is poorly written, unnecessary in light of existing offences and unfairly targets football fans.

Conservative MSP Douglas Ross put forward a motion for debate underlining that "sectarian behaviour and hate crime are a blight on society in Scotland and should not be tolerated under any circumstances", but adding that "there are laws in place to prosecute acts of hatred" other than the OBFA.

The motion also "notes with concern that the legal profession has repeatedly criticised the Act for being unworkable and badly drafted", "regrets that the Scottish government hastily pushed the legislation through" and "urges the Scottish government to repeal the act as a matter of priority".

Image caption Qualified linesman Douglas Ross put a motion forward for the Tories

Analysis by Brian Taylor, BBC Scotland Political Editor

So what now? Do I think the Justice Secretary Michael Matheson will tear up the act tonight?

I do not. However, ministers have signalled that they will review the legislation.

In the initial stages of that review, I expect them to focus primarily on two aspects.

I expect them, firstly, to argue strongly in favour of the section of the Bill covering Online communications, to stress its worth whatever the final verdict on the football section.

I expect them, secondly, to challenge their opponents to say what might reasonably replace the Act.

As of tonight, the Opposition parties are demanding straightforward repeal, arguing that existing statute - for example, on breach of the peace - is sufficient without, they argue, provoking unrest among football fans and potentially provoking conflict with the police.

Read more from Brian here.

All four opposition parties supported Mr Ross's motion.

For Labour, Mr Kelly said the act had been a "failure", arguing it was ineffective in combating sectarianism. He said there should not be a law that targets one section of sports fans alone.

Scottish Greens MSP John Finnie said there was consensus that sectarianism needed to be tackled, but "there never was a shared political vision for this act".

Liam McArthur of the Liberal Democrats said the legislation was "flawed from the start". He said "sectarianism must be shown the red card", but added that the OBFA should also get an "early bath".

Murdo Fraser of the Conservatives closed the debate by saying there were better ways to "send a message" about sectarianism than by criminalising young football fans.

'Ugly brothers'

However SNP members rallied behind the act, with James Dornan claiming that opposition parties were more interested in defeating the government than improving the legislation.

He said sectarianism and football were "ugly brothers", adding that "the defining picture of sectarianism in Scotland has always been football".

Image copyright PA Image caption Football supporters including the Fans Against Criminalisation group have staged rallies against the Act

Justice Secretary Michael Matheson said he was struck by the "lack of alternative approaches" suggested by opposition members, drawing particular attention to the part of the legislation dealing with threatening communications.

When the matter came to a vote, the motion was passed by 64 votes to 63. An SNP amendment was rejected by the same margin.

Mr Kelly raised a point of order after the debate, saying the football act was "dead in the water" and calling for "immediate" plans from the government on how it would be repealed.

Presiding Officer Ken Macintosh said parliament had "made its voice clear" and said it was for the government to decide how to reflect that.

Minister for Community Safety Annabelle Ewing subsequently said the vote "threatens to set us back as a country in our efforts to effectively combat prejudice, hate crime and sectarianism".

She added: "The result of the vote sends completely the wrong message about how serious parliament as a whole is about doing so - but the Scottish Government remains absolutely committed to that objective.

"Evidence shows strong public support for this legislation, the repeal of which would leave a significant gap in effectively prosecuting hate crime."