Sexual encounters with archaic humans like Neanderthals have endowed modern humans with genes that contribute to our greatly improved immune system, according to researchers.

Mating with Neanderthals and another ancient group called Denisovans introduced genes that help us cope with viruses to this day, they conclude, reports BBC News.

DNA inherited from Neanderthals and newly discovered hominids known as Denisovans has contributed to key types of immune genes still present among populations in Europe, Asia and Oceania.  Scientists believe that these gene variants must have helped humans survive while migrating throughout the world.

The cross-breeding wasn't just a random event that happened, it gave something useful to the gene pool of the modern human, said Stanford University's Peter Parham, senior author of the study in the journal Science.

Scientists already knew that about four percent of Neanderthal DNA and up to six percent of Denisovan DNA are present in some modern humans.

The new study looked at the origins of some HLA (human leucocyte antigen) class 1 gene and traced it back to our ancient relatives. (HLA) class I genes are responsible for making HLA proteins that help the immune system adapt to defend against new pathogens that could cause various infections, viruses and diseases. They found evidence that a variant of HLA called HLA-B*73 found in modern humans,came from cross-breeding with Denisovans. Similarly HLA gene types were found in the Neanderthal genome.

We are finding frequencies in Asia and Europe that are far greater than the whole genome estimates of archaic DNA in modern humans, which is 1-6 percent, said Professor Parham.

Scientists believe that Europeans owe more than half their variants of one class of HLA gene to interbreeding with Neanderthals and Denisovans. Asians owe up to 80 percent, and Papua New Guineans up to 95 percent.

Ancient pre-human people, like the Neanderthals and Denisovans, apparently left Africa some 400,000 years ago and wandered through Europe and Asia until modern humans came to Eurasia from Africa around 85,000 years ago, and quickly replaced them, Parham said.

Modern humans overran the Neanderthals from Northern Europe to Spain, and by 30,000 years ago the Neanderthals were gone. Similarly, humans also overran the Denisovans in Siberia and they disappeared at about the same time. But some of their genes lived on in humans, Parham's team reported.

Since the Denisovans had been living in Europe and Asia for several hundred thousands of years, their genes had adapted to life in these regions. However since the recent migrants from Africa did not have these genes, those who acquired them by mating got an advantage, added Parham. Those who stayed in Africa did not get the healthy immune system genes.