Austria must compensate an ex-policeman who was sacked in 1976 for sexual indecency with minors and who lost 25% of his police pension, the European Court of Justice (ECJ) has ruled.
He committed the offence with two boys aged 14 and 15. The age of consent was 18 for male homosexuals at the time.
The man, identified only as EB, also got a three-month suspended jail term.
The ECJ did not challenge that penalty, but said he was owed his lost pension, going back to December 2003.
That was when Austria implemented an EU anti-discrimination directive. The judges in Luxembourg say it was wrong to continue the 25% pension deduction beyond that date.
"It's wonderful that the judges have ended this discrimination, after 10 years in court," the man's lawyer Helmut Graupner told the BBC.
The Vienna police were openly scornful of homosexuals back in 1976, according to Austrian LGBT rights group RK Lambda.
The police disciplinary panel had referred to EB's "deviant tendencies". "A man whose homosexual tendencies were known beforehand would hardly be accepted into the security service!" the panel had said.
Why this ruling, if he committed an offence?
EB, who wishes to remain anonymous, was sentenced under an old paragraph in the Austrian penal code that was scrapped in 2002.
He is 77 now and argued that the continuing pension deduction was discriminatory, contradicting Austria's updated law. That was the focus of the case, not EB's indecency conviction.
EB's case had gone through the Austrian courts for years before being referred in 2009 to the ECJ, the European Union's top court. After this decades-long legal fight, he finally won his case at the ECJ on Tuesday.
Under the old law, the age of consent was set at 18 for homosexual men, but at 14 for lesbians and heterosexuals.
In 2002, in line with EU anti-discrimination policy, Austria made 14 the age of consent for everyone, although workers in the sex industry have to be 18 or older.
Austria also changed the disciplinary code for public servants, so "sex in your private life cannot be grounds for disciplinary sanction today", Mr Graupner said.
EB's suspended three-month jail term in 1976 included an order to fast for one day a month. He had served in the police for 13 years before being sacked.
Read more on gay rights:
How much compensation should EB get?
The 25% monthly deduction from EB's pension - part of the penalty imposed back in 1976 - is €175 (£154; $200) before tax, Mr Graupner said.
The lawyer calculated the annual loss for EB to be €2,450, and said that after 15 years from 2003-2018 the total would be €36,750 before tax.
What are the wider implications?
The ruling - binding on Austria - is another victory for campaigners who have fought for decades against homophobic laws.
Austria has also lost 10 age-of-consent cases over the now-defunct law at the European Court of Human Rights, which is separate from the EU.
In one case a 17-year-old Austrian won compensation after arguing that he was not free to choose older partners, as they risked prosecution for having sex with him.
This month same-sex marriage became legal in Austria, making it the 15th EU country to take that step.
Mr Graupner said there could be cases in the UK similar to the Austrian one, "if there are still negative effects in pension payments pre-dating the EU anti-discrimination directive".