A transgender woman who was unable to access her pension was discriminated against by UK law, the European Court of Justice has found.
The woman - known as MB - was refused the female state pension at 60 because she chose not to annul her marriage.
MB said she preferred to stay married to her wife "in the sight of God".
But a court has ruled a person who has changed gender does not have to annul the marriage they entered into before that change, to receive a pension.
Under the UK's 2004 Gender Recognition Act, trans people acquired the right to formally change their gender by obtaining a full "gender recognition certificate".
But the law states a certificate cannot be issued to a married person who does not have their marriage annulled on the basis of their gender change.
In the UK, women born before 6 April 1950 can apply for a state pension at age 60, while men born before 6 December 1953 must wait until 65.
MB, who was born male in 1948, married in 1974 and had two children. In 1991, MB began to live as a woman and underwent gender reassignment surgery in 1995, but did not apply for a gender recognition certificate.
When she reached her 60th birthday in May 2008, MB applied for a state pension, but was refused on the basis that legally she was still a man, and should therefore wait for the male pension at 65.
MB challenged the decision and her case went to the UK Supreme Court, where the judges were "divided" on the issue.
Supreme Court judges referred it to the EU Court of Justice for guidance.
The ECJ found that the UK's marriage annulment condition (designed to avoid marriage between persons of the same sex) is "unrelated" to the retirement pension scheme.
And so it concluded that UK legislation "constitutes direct discrimination based on sex" and is therefore in breach of European law.
MB's lawyers - Jacqueline Mulryne of Arnold & Porter and Chris Stothers of Freshfields Bruckhaus Deringer - said they were "delighted" at the decision.
"After almost a decade, MB will finally be paid her pension and recognised as a woman by the government," they said in a statement.
"This is a small decision but it has great importance in the move towards increased equality and respect."
The case will now return to the Supreme Court to apply the ruling, but MB's lawyers said they are "hopeful" the Department for Work and Pensions will apply the ruling "without delay".