A study found that animals have sex and reproduce together, rather than simply cloning themselves, because it helps them to ward off parasites.
Researchers working at Indiana University in the US used the round worm Caenorhabditis elegans to test the theory.
They exposed worms to harmful bacteria, and found that worms that reproduced through sex survived fairly well while those that were asexual died rapidly.
The researchers say the results are the most convincing evidence to date for a key theory in evolutionary biology.
The theory holds that sex evolved because it lets organisms reshuffle their genes into new combinations to stay a step ahead of parasites.
"What is really beautiful about these lab systems is that you can manipulate the system and show that [the theory] can work," the BBC quoted evolutionary biologist Aneil Agrawal from the University of Toronto in Canada, as saying.
Dr Agrawal described the experiment as "elegant" because it allowed the researchers to demonstrate that it was not simply the presence of the parasite that spelled the end for the cloners, but the presence of a parasite that had co-evolved alongside the worms.
"I am really excited about this; I think this is really cool," Dr Agrawal said.
"Whether this is actually happening in nature is another thing; we can't know that from a lab system," he explained.
But he adds that as a first step it is important to demonstrate that under conditions where you expect sex to alleviate the effects of parasites, it does.
Biologists have described the situation as "Running with the Red Queen" in reference to the character in Lewis Carroll's Through the Looking-Glass, who tells Alice: "It takes all the running you can do, to keep in the same place."
"The Red Queen Hypothesis predicts that sex should allow hosts to evade infection from their parasites, whereas self-fertilisation may increase the risk of infection," co-author Curtis Lively said.
"The co-evolutionary struggle between hosts and their parasites could explain the existence of males," he added.
The findings have been published this week in the journal Science.