Scotland’s First Minister Nicola Sturgeon has formally apologised to gay men criminalised by once illegal sexual offences, calling it a "historic wrong".
Her apology, on behalf of the Scottish Government, spoke about those convicted of homosexual acts that were once against the law.
It came before a debate in which she set out plans for a new law at Holyrood to pardon them for their historic convictions.
The legislation will also enable the men to apply for their convictions to be removed from central criminal conviction records.
It has been dubbed Scotland's "Turing Law" after codebreaker Alan Turing, who was given a posthumous royal pardon after being convicted in 1952 for gross indecency.
Ms Sturgeon told the Scottish Parliament that the new legislation puts right "a historic wrong".
She said: "For people convicted of same-sex sexual activity which is now legal, the wrong has been committed by the state to them, not by individuals. These individuals therefore deserve an unqualified apology as well as a pardon."
She said the new bill would not "erase those injustices" but that she hoped it could "provide some comfort to those who endured those injustices".
In Scotland, consensual sexual acts between men over 21 were decriminalised in 1981. It was not until 2001 that the age was lowered to 16.
The new Holyrood legislation - the Historical Sexual Offences (Pardons and Disregards) Bill - was supported by Scottish Conservative leader Ruth Davidson, who said: "Scotland is a better place to be gay than at any time in my lifetime and this action will make it better still."
LBGTI support groups have also welcomed the bill.
Tim Hopkins, director of the Equality Network, said it would be of "direct importance to hundreds of people with past criminal convictions for the kinds of relationships that were perfectly legal for their heterosexual friends".
Stonewall Scotland called it an "important moment" that enables the country to "draw a line, once and for all, under a dark period in Scotland's history".
The move in Scotland has not been reflected south of the border.
Westminster's policing and crime act only seeks to pardon men who were convicted of same-sex offences who have since died.
Men convicted of such offences in England and Wales who are still alive have to apply to the Home Office to have criminal records erased.