British and German scientists say they have identified a gene that is responsible for keeping ovaries what they are, the 'female' gene,' as it were.
When the gene is switched off, the ovary starts to turn into a testicle and makes the male sex hormone testosterone.
The research, detailed in the respected journal Cell, centred on two genes, one called Sox9, which is crucial for the development of testes in the womb, and another called FoxL2.
When the scientists used a genetic trick to switch off Sox9 in adult female mice, FoxL2 rapidly sprung into action.
The animals' eggs shrivelled up and the cells in their ovaries turned into those found in the testicles, including a type the nurse sperm through their development. Other cells started to produce testosterone.
However, the 'female' mice did not make sperm.
Researcher Mathias Treier, of the European Molecular Biology Laboratory in Heidelberg, said: 'No one would have bet on this. That's why the finding is so spectacular.'
Co-author Robin Lovell-Badge, of the Medical Research Council's National Institute for Medical Research in London, said: 'We take it for granted that we maintain the sex we are born with, including whether we have testes or ovaries.
'But this work shows that the activity of a single gene, FoxL2, is all that prevents adult ovary cells from turning into cells found in the testes.'
The work could help understand and one day treat premature menopause. One per cent of British women go through the menopause before they hit 40 and some are just in their teens when their periods stop.
It could also lead to drugs that allow women to give their ovaries 'a rest', temporarily freeing them from the misery of periods and preserving the cache of eggs they are born with.
The option of delaying menopause would appeal to women waiting to meet 'Mr Right' and to those who want to build their careers and bank balance before starting a family.
Dr Lovell-Badge said: 'FoxL2 is certainly a very important gene for maintaining and ovary as an ovary and for ovarian function.
'Maybe what you would want to do is stop the ovary from working for a while.
'It would be kind for it and for women.'
The ability to turn ovaries into testes could also remove the need for some of the surgery involved in sex-change operations.
The gene FoxL2, which is located on a non-sex chromosome called an autosome and therefore present in both sexes, was known to play an important role in the female pathway but its precise function remained elusive.
In humans and most other mammals, an individual's sex is determined by its sex chromosomes - females have two X chromosomes, males have one X and one Y.
Scientists had long assumed that the female pathway - the development of ovaries and all the other traits that make a female - was a kind of default: if it had a gene called Sry, which is located on the Y chromosome, an embryo would develop into a male, if not, then the result would be a female.
But in adult animals it is the male pathway that needs to be actively suppressed, as Dr Treier and his researchers discovered.
They showed that FOXL2 helps to repress a DNA element called TESCO that regulate expression of the testes-promoting gene Sox9 which makes the early gonads become testes rather than ovaries.
But the new research suggests it can perform the same task in the adult.
FOXL2 is therefore critical to keep Sox9 turned off in ovaries throughout life.
Dr Lovell-Badge said: 'As most vertebrates have Foxl2, estrogen receptors and Sox9, this mechanism for maintaining female traits probably appeared early on in the evolution of vertebrates, while Sry and the mammalian Y chromosome are relatively new inventions.
'It could have implications for the early menopause as a surprisingly high proportion of young women suffer from premature ovarian failure.'
The findings will have wide-ranging implications for reproductive medicine and may, for instance, help to treat sex differentiation disorders in children, for example where XY individuals develop as females or XX as males, and understand the masculinising effects of menopause on some women.
Further analysis showed that FOXL2 works in co-operation with the estrogen receptor to repress Sox9. Without FOXL2, the estrogen receptor fails to work suggesting that loss of estrogen levels could lead to sex reversal.
Dr Treier suspects that this mechanism might underlie the occasional signs of masculinisation seen in menopausal women.