Thirty-four years ago, doctors in Los Angeles discovered that some of their patients were succumbing to a normally harmless fungus. It soon became clear that they belonged to a growing number of people whose immune systems were hobbled by a virus, eventually known as human immunodeficiency virus, or H.I.V.

To date, an estimated 78 million people have become infected, 39 million of whom have died.

As the true scale of the virus’s devastation began to emerge, a number of scientists set out to investigate its origins. Piece by piece, year after year, the scientists reconstructed its history. Their research slowly revealed that the virus did not make a single leap from animals, but several.

On Monday, a team of researchers filled in the final gaps in the history. It’s now clear, they say, that the virus originated in humans on 13 separate occasions, evolving in humans from ancestral viruses that infected monkeys, chimpanzees and gorillas.

“We’ve got an amazing amount of the story nailed down, more than any reasonable person could have expected in the 1980s,” said Michael Worobey, a professor of ecology and evolutionary biology at the University of Arizona, who was not involved in the new study.