MSPs are to pass a law that will automatically pardon gay and bisexual men who were convicted of sexual offences that are no longer illegal.
Consenting sexual activity between men over the age of 21 was only decriminalised in Scotland in 1981.
It was a further 20 years before the age of consent for gay men was lowered to 16.
The new law will pardon men convicted of having consensual sex with other men before it was decriminalised.
It will also enable men to apply to have convictions for same-sex sexual activity that is now legal removed from central criminal conviction records.
But it will not apply to behaviour that is still illegal today – for example rape or having sex with someone under the age of 16.
The Historical Sexual Offences (Pardons and Disregards) Bill has received strong cross-party support since being introduced by the Scottish government in November.
At the time, First Minister Nicola Sturgeon offered an “unequivocal apology” to men who had been “convicted as criminals, simply for loving another adult”.
She said: “Those laws criminalised the act of loving another adult, they deterred people from being honest about their identity to family, friends, neighbours and colleagues.
“By sending a message from parliament that homosexuality was wrong, they encouraged rather than deterred homophobia and hate.
“Nothing that this parliament does can erase those injustices, but I do hope this apology, alongside our new legislation, can provide some comfort to those who endured those injustices.”
Why were gay men prosecuted?
Before the law changed, men were prosecuted for offences including consensual sexual activity in private, kissing another man in a public place, or just chatting up another man in a public place – which was known as “importuning”.
Such behaviour was legal at the time between a man and a woman, and is legal today between two men.
The Equality Network charity estimates that the total number of these historical convictions in Scotland runs into thousands, and that there are hundreds of men alive today with such convictions on their records.
Sex between women was never criminalised in this way in Scotland, and the same rules applied to it as applied for sex between a man and a woman.
What will the new law actually do?
The bill will give an automatic formal pardon to people, both living and dead, who were convicted of historical sexual offences where the conviction was for conduct which is now legal.
However, the pardon is a purely symbolic acknowledgement that the laws were discriminatory, and does not reverse the conviction.
Anyone with a historical conviction for same-sex sexual activity that is now legal would have to apply for a formal “disregard” in order to prevent the information being included in disclosure checks.
It would then be up to Scottish ministers to decide, based on the available evidence about the specific case, whether the disregard is granted.
A successful disregard application means the conviction will not appear on any background check carried out by Disclosure Scotland, and the person will be treated as not having committed the offence.
What is the situation elsewhere in the UK?
About 49,000 gay and bisexual men convicted of now-abolished sexual offences in England, Wales and Northern Ireland received posthumous pardons in January last year.
Thousands of living men convicted over consensual same-sex relationships were also eligible to apply to have their convictions removed.
It followed the pardoning in 2013 of World War Two code-breaker Alan Turing, who had been convicted of gross indecency.
Private homosexual acts between men aged over 21 were decriminalised in England and Wales in 1967.
The Equality Network says the Scottish legislation does a better job than the equivalent law elsewhere in the UK as it provides an automatic pardon to people who are still alive, and also covers all of the old discriminatory offences.