THOUSANDS of gay and bisexual men convicted under previous discriminatory laws are to be given automatic pardons under landmark legislation.

MSPs voted unanimously in favour of the reform, which also lets people apply to have past convictions scrubbed, or “disregarded”, from their criminal records.

Consensual sex between men over the age of 21 was illegal in Scotland until 1981, and the age of consent was only lowered to 16 in 2001.

Although the pardon is essentially symbolic, it is wider in scope than a version south of the border, as it applies both posthumously and to those still living.

It also covers the full range of previous discriminatory laws which applied to gay man, including “importuning”, which was essentially chatting someone up in public.

Such behaviour was legal at the time between men and women, and women and women.

When the SNP Government introduced the Historical Sexual Offences (Pardons and Disregards) Bill last year, Nicola Sturgeon offered an unreserved apology to the men it was intended to help, and said it was “shocking” the law had punished them until so recently.

As the Bill passed its third and final stage at Holyrood on Wednesday by 119 votes to zero, Justice Secretary Michael Matheson said the legislation marked a “proud day for Scotland”.

He said: “Hopefully those, who should never have been branded criminals in the first place, will now feel justice has been restored. But we cannot rest on our laurels - discrimination and inequality remain all too prevalent in society and we must continue to tackle them.”

Tory MSP Annie Law said the law would bring “true LGBTI equality” closer and give men convicted under the historical laws “the opportunity to really move on with their lives”.

Labour's Daniel Johnson said: “This process of a public acknowledgement that our laws were wrong is a historic moment for equality, acceptance and respect in our country.

“Hopefully those, who should never have been branded criminals in the first place, will now feel justice has been restored.”

LibDem Alex Cole-Hamilton said the old laws had been a “stain on our national conscience”, and the change offered a “profound and unreserved apology to those men both alive and dead who have been done incalculable harm by the policies and laws of the past”.

Green MSP Patrick Harvie said the previous legal regime amounted to “indefensible actions by the state against its own citizens, in defiance of their dignity and their basic human rights”.

Like many MSPs, he said the new law was welcome but not sufficient, and all parties had to keep fighting to make anti-LGBTI bigotry as unacceptable as racism or anti-Semitism

However there was also a row, when SNP backbencher John Mason said “traditional faith communities” still believed it was “wrong for one person of the same sex to have a sexual relationship with someone else”, although he voted for the Bill regardless.

The Equality Network estimated the number of discriminatory convictions in Scotland runs into thousands, with hundreds of men alive today with convictions on their records.

Director Tim Hopkins said the change was “concrete recognition of the huge harm that was done to people who were prosecuted or lived under these old laws.

“Together with the First Minister’s public apology in Parliament in November, the message is that Scotland has changed for good, and that discrimination is no longer acceptable.”

“The next stage will be to implement and publicise the new law. Publicity will be crucial so that all those affected by these historical convictions get to hear about it.”

The law is expected to come into effect towards the end of the year.