The first minister is to apologise on behalf of the Scottish government to gay men convicted of now-abolished sexual offences.
Nicola Sturgeon will make the apology at Holyrood on 7 November to coincide with new legislation giving an automatic pardon to those affected.
The legislation was promised by Ms Sturgeon when she presented her programme for government in September.
The law will also allow the removal of such crimes from criminal records.
A Scottish government spokesman said that Ms Sturgeon would apologise to those convicted prior to 2001 under discriminatory laws against same-sex sexual activity that is now legal.
He added: “The apology will be made on behalf of the Scottish government for the treatment of homosexual men under previous governments and will coincide with the introduction of legislation to provide people convicted under these laws an automatic pardon.
“The bill will right a historic wrong and give justice to those who found themselves unjustly criminalised simply because of who they loved.”
The legislation was first confirmed by Justice Secretary Michael Matheson in October last year.
He announced plans for automatic pardons just days after similar legislation was scuppered at Westminster.
That happened after a private member’s bill by the SNP’s John Nicolson, which would have pardoned all men living with UK convictions, was “talked out” of the Commons.
The UK government failed to support that private members bill in favour of bringing forward its own plans.
Under its Policing and Crime Act, gay and bisexual men convicted of now-abolished sexual offences in England and Wales received posthumous pardons. Those who are living can be pardoned after the secretary of state agrees the conduct is no longer criminal.
Tim Hopkins, director of the Equality Network, said: “The apology is important because it shows that it was the discriminatory laws that were wrong, and not the consensual relationships that were made criminal by those laws.
“We look forward to seeing the detail of the bill.
“If it implements the policy announced by the Scottish government, it will be a hugely important statement that Scotland regrets the discrimination of the past, and now considers its LGBTI people to be fully equal citizens who deserve equal respect.
“It will also be of direct practical importance to people who currently have one of these convictions show up on criminal record checks for jobs or volunteer posts.”