The prisoner would be moved "as soon as possible", the court heard
The refusal to move a pre-operative transsexual prisoner from a men's jail to a women's prison is a violation of her human rights, says the High Court.
Deputy Judge David Elvin QC quashed Justice Secretary Jack Straw's decision to keep the 27-year-old, who cannot be identified, in a male prison.
Referred to as "A", she is serving a life sentence for manslaughter and attempted rape, committed when a man.
The Prison Service said it was "disappointed" at the ruling.
A spokesman added that the Service was "studying it carefully and will consider whether to appeal".
London's High Court heard the prisoner should be moved within a few weeks.
Although born male, "A" suffered from gender dysphoria - the feeling of being trapped in the body and role of the wrong sex - and had known of her condition from an early age, said Deputy Judge Elvin.
During her imprisonment, she has had body and facial hair removed by laser and her breasts developed by hormone treatment.
In 2006, she was recognised as a woman "for all purposes" under the Gender Recognition Act 2004.
In her evidence, "A" said: "That felt like an important stage. No-one can take my female status away from me. Till the day I die I will be a woman.
"For me it is simply a reflection of how it should have been from the start."
She is now seeking gender reassignment surgery, but has been told by a gender identity clinic that it cannot take place until she has lived "in role" as a woman "within a female prison".
The judge said: "It follows that, so long as the claimant remains within the male prison estate, she is unable to progress towards the surgery which is her objective."
This "interferes with her personal autonomy in a manner which goes beyond that which imprisonment is intended to do", he said.
"I declare her continued detention in a male prison is in breach of her rights under Article 8 (right to private and family life) under the European Convention on Human Rights."
The judge said that the claimant's transition to womanhood "goes to the heart of her identity. It appears to be closely related to her offending behaviour".
The prisoner is serving an automatic "two strikes" life sentence for manslaughter "by reason of provocation of her male partner" in 2001, and attempted rape of a female stranger days after her release from that five-year manslaughter term.
She has been eligible for parole since 2007, but has been considered a continuing risk to the public.
"A" now dresses as a woman in prison, subject to restrictions on some items items of clothing and make-up, living - for her own protection - in a single cell in a vulnerable prisoners unit.
The judge said: "While the outcome of these proceedings does not turn on this issue, the restrictions placed on the claimant exceed those which would apply if she were resident in the female prison estate."
Her gender dysphoria and appearance had seriously affected her ability to engage in "offending behaviour" work and make progress towards her release on licence, he added.
The risk presented "both to herself and others if she perceives that her treatment is being delayed or withdrawn" had already been recognised, he said.
Barrister Phillippa Kaufmann, for the prisoner, told the court: "An indication has just been given to us that the transfer should be effective in a few weeks."
The Ministry of Justice and prison authorities had argued that "A" was no more likely to be accepted at a women's prison, where she would require long periods of segregation at an extra cost of £80,000 a year.
They also argued that transfer might have a serious impact on her mental health, making it more difficult for her to reduce her level of risk to society and win early release.