It’s an evolutionary paradox that’s frustratingly difficult for biologists to explain, but researchers may have just found a benefit conferred by homosexual sex that could offer an explanation as to why this behavior has persevered, at least in one species. According to a new study in fruit flies, not only does same-sex sexual behavior seem to be heritable, but females with a genetic makeup associated with this trait actually display higher reproductive rates, which is an evolutionary advantage. These fascinating findings have been published in Proceedings of the Royal Society B.

If a certain trait or behavior is detrimental to the reproductive success, or fitness, of an organism, you wouldn’t expect it to persist in the population as natural selection should get rid of it. After all, the aim of the reproductive game is to keep your genes going. Why, then, do members of the same sex cop off with each other in so many species? And we’re not just talking about homosexual behaviors (observed in more than 1,500 species, since you asked); we mean the whole shebang.

Scientists have long pondered this and have struggled to come to any consensus. Although there are a few different ideas, two prevailing hypotheses that resulted from theoretical work suggest that same-sex sexual behaviors (SSB) could persist for two reasons: overdominance and sexual antagonism. The former proposes that SSB could persist in the population if genes for this behavior confer a harmonizing reproductive advantage in individuals only possessing one copy of the gene, or heterozygotes, as opposed to those in possession of two (homozygotes). The latter suggests that a gene that is detrimental to fitness in one sex could be maintained so long as it is beneficial to the other sex.

So how do researchers work out which hypothesis seems to better explain this behavior that is seemingly harmful to reproduction? The method chosen by scientists behind the latest study, based at the University of St. Andrews, involved a combination of genetic and behavioral tests. First, they screened inbred fruit fly lines in search of gene variations that could account for SSB.

They did this by both examining the genomes of male fruit flies and observing how they behaved with other males. This involved quantifying the amount of courtship behaviors males would display towards other males—such as licking, singing or attempted mounting—and then looking for genetic differences present in males displaying high levels of these behaviors. This information was then used to identify genetic lines of flies that either consistently showed high levels of SSB, or low levels of SSB.

The final stage of the investigation involved performing experimental crosses of flies from both of these identified lines and examining the resulting offspring. More specifically, they wanted to see whether coming from a genetic background associated with high levels of SSB affected reproductive rates in female offspring.

The researchers found that while their data lent more weight to the overdominance hypothesis, their results did not exclusively support one over the other. In fact, they think that both could be contributing to the maintenance of SSB in the gene pool. But that wasn’t the most interesting find of the study: Males with a genetic makeup associated with high levels of SSB produced female offspring with higher rates of reproduction, or fecundity. This suggests that genes associated with SSB could be persisting in the population because they actually confer a fitness advantage in females, despite being reproductively harmful to males.