There is a little Neanderthal in nearly all of us, according to scientists who compared the genetic makeup of humans with that of our closest ancient relatives.

Most people living outside Africa can trace up to 4% of their DNA to a Neanderthal origin, a consequence of interbreeding between the two groups after the great migration from the contintent.

Anthropologists have long speculated that early humans may have mated with Neanderthals, but the latest study provides the strongest evidence so far, suggesting that such encounters took place around 60,000 years ago in the Fertile Crescent region of the Middle East.

Small, pioneering groups of modern humans began to leave Africa 80,000 years ago and reached land occupied by the Neanderthals as they spread into Eurasia. The two may have lived alongside each other in small groups until the Neanderthals died out 30,000 years ago.

Scientists led by Svante Pääbo at the Max Planck Institute for Evolutionary Anthropology in Leipzig took four years to sequence the whole Neanderthal genome from powdered bone fragments taken from three females who lived in Europe 40,000 years ago.

To see how similar the Neanderthal was to modern humans, the team compared the ancient DNA with the genomes of five people from France, China, southern Africa, western Africa and Papua New Guinea. The study is the first to attempt a whole-genome comparison between Neanderthals and modern humans.

The researchers found that modern humans and Neanderthals shared 99.7% of their DNA, which was inherited from a common ancestor 400,000 years ago. Further analysis revealed that Neanderthals were more closely related to modern humans who left Africa than to the descendants of those who stayed. Between 1% and 4% of the DNA in modern Europeans, Asians and those as far afield as Papua New Guinea, was inherited from Neanderthals.

"Those of us who live outside Africa carry a little Neanderthal in us," said Professor Pääbo. "Neanderthals probably mixed with early modern humans before Homo sapiens split into different groups in Europe and Asia. The comparison of these two genetic sequences enables us to find out where our genome differs from that of our closest relative."

Interbreeding between humans and Neanderthals may nonetheless have been rare. Just two Neanderthal females in a group of around a hundred humans would have been enough to leave such a trace in our genome, provided that was the group that gave rise to all modern humans outside Africa.

The study, reported in the journal Science, was greeted by scientists as almost certain confirmation that modern humans and Neanderthals mated when the groups crossed paths. "It certainly tells us something about human nature," said Chris Stringer, head of human origins at the Natural History Museum in London.

Ed Green, a senior author on the study at the University of California, Santa Cruz, said: "How these peoples would have interacted culturally is not something we can speculate on in any meaningful way. But knowing that there was gene flow is important, and it is fascinating to think about how that may have happened."

He added: "The scenario is not what most people had envisioned. We found the genetic signal of Neanderthals in all the non-African genomes, meaning that the admixture occurred early on, probably in the Middle East, and is shared with all descendants of the early humans who migrated out of Africa."

The German group has yet to investigate what purpose, if any, the Neanderthal genes play in modern humans. But the study did highlight several genes that are unique to modern humans. They are thought to be involved in the development of brain function, features of the skull, metabolism and formation of the collar bone and rib cage.

"A major next step will be to find out not only what the unique human genes are doing, but whether the genes we've got from Neanderthals are of functional significance. Is there something in the biology of people outside Africa that is coming from those Neanderthal genes?" said Prof Stringer.