Germany's cabinet has backed a bill to clear men handed sentences for homosexuality after World War Two under a Nazi-era law.
The notorious Paragraph 175 of the penal code was eventually relaxed in 1969, but not before 50,000 men were convicted.
Many were sent to jail and some took their own lives because of the stigma.
Justice Minister Heiko Maas said it was a flagrant injustice and those still alive would be given compensation.
The German government's decision comes months after the UK said it was pardoning 65,000 gay and bisexual men who were convicted under the Sexual Offences Act that criminalised private homosexual acts in England and Wales until 1967 and later in Scotland and Northern Ireland.
What will quashing the sentences mean?
The cabinet decided on Wednesday to back a bill annulling the sentences and handing compensation to all those affected.
If the law is passed, every man convicted who is still alive will receive a €3,000 (£2,600; $3,240) lump sum plus a further €1,500 for each year spent in jail.
Only 5,000 men are thought to be eligible for compensation as most have since died.
Condemning the convictions as the "crimes of the state", the justice minister said the men's rehabilitation was long overdue.
"It was only because of their love of men and their sexual identity that they were persecuted, punished and outlawed by the German state," said Mr Maas.
What was Paragraph 175?
The law prohibiting "sexual acts contrary to nature" first appeared in Germany's criminal code in 1871 shortly after the country was unified.
Unsuccessful attempts were made to repeal it under the Weimar Republic, but under the Nazis it was tightened in 1935 to criminalise "lewd and lascivious acts" between men. Tens of thousands of homosexuals were imprisoned and many died in concentration camps.
The article remained part of the criminal code in East and West Germany. In the East it was removed in 1968 and in the West it was relaxed before being finally repealed by the unified German government in 1994.
Between 1949 and 1969 50,000 men were prosecuted and there were a further 14,000 cases until 1994.
Wolfgang Lauinger, now 98, was persecuted first by the Nazis and then held in prison uncharged for several months in 1950 by the West German authorities.
"I still believe they used old Gestapo files," he said of his post-war interrogators in a 2016 interview.
What is the Turing law?
Alan Turing was both a renowned mathematician and World War Two codebreaker when he was convicted of gross indecency in 1952 for having sex with a man. He lost his job, was chemically castrated and two years later took his life aged 42.
He was finally pardoned in 2013.
In January 2017, the UK government granted a posthumous pardon under the "Turing law" to an estimated 50,000 men convicted of having consensual homosexual sex.
Some 15,000 are still alive but have to apply to have their conviction removed under a "disregard process". No compensation is involved.