A women's group has convinced judges that an attempt by the Scottish government to expand the definition of "woman" to include transwomen breaches equality law.
For Women Scotland appealed against a 2021 ruling that backed the government.
The Court of Session ruled that the definition in the Gender Representation on Public Boards Scotland Act 2018 could only cover biological women.
The act's purpose is to ensure greater gender balance on public sector boards.
For Women Scotland's QC, Advocate Aidan O'Neill, challenged the earlier ruling.
He said the Scottish government's proposals to help transgender people gain greater representation on public boards undermined the rights of women under the Equality Act.
In a judgment, Lady Dorrian and her colleagues upheld Mr O'Neill's submissions.
Lady Dorrian, who delivered the decision, wrote that by incorporating those living as women into the definition of woman, the 2018 Act "conflates and confuses two separate and distinct protected characteristics".
She said the Scottish Parliament could have included an equal opportunities objective to encourage representation of women on boards, and separately for any other protected characteristic. However, this had not been done.
Lady Dorrian also said that changing the definition of protected characteristics was not permitted and was not within the legislative competence of the Scottish Parliament.
Lawyers for the Scottish government denied the Holyrood administration had acted unlawfully.
At the proceedings last year, For Women Scotland had argued that the Scottish government could not legislate on equalities law as it was reserved to the UK Parliament.
However, Scottish government lawyer Ruth Crawford QC said the law allowed for the government to legislate on the matter.
She said the proposed redefinition of the word "woman" would broaden the term to include transgender women, who have the protected characteristic of gender reassignment under the Equality Act 2010.
At the time, Judge Lady Wise said the proposed changes did not breach the Equality Act 2010 and that the Scottish government could legislate on the matter.
In her judgment, Lady Dorrian added that the judges had heard submissions critical of the process involved in obtaining a gender recognition certificate. She said policy issues around, for example, the Gender Recognition Act 2004 were beyond the scope of the case.
The ruling comes the day after Lord Sandison ruled a government plan to allow people to "self-identify" when answering a question about their sex in this year's census was lawful.