HIV, which causes Aids, emerged in humans in the 20th Century, but scientists have long known that similar viruses in monkeys and apes have existed for much longer.
A genetic study shows HIV-like viruses arose in African monkeys and apes 5 million to 12 million years ago.
The research may one day lead to a better understanding of HIV and Aids.
HIV affects 34 million people worldwide.
The disease emerged during the 20th century after a HIV-like virus jumped from chimps to humans.
Scientists have long known that similar viruses, known as lentiviruses, are widespread in African primates.
Past genetic research has suggested these "cousins" of HIV arose tens of thousands of years ago, but some experts have suspected this is an underestimate.
Scientists at the University of Washington in Seattle, US, and the Fred Hutchinson Cancer Research Center, also in Seattle, looked at the genetic signatures of HIV-like viruses in a number of primates, including chimps, gorillas, orang utans and macaques.
Changes in genes that have evolved in the immune systems of monkeys and apes in Africa suggest the viruses arose between 5 and 16 million years ago.
The research, published in the journal PLOS Pathogens, gives clues to how the immune systems of our closest relatives evolved to fight infection.
Dr Michael Emerman of the Fred Hutchinson Cancer Research Center said: "Our study reveals that, while primate lentiviruses may have modern consequences for human health, they have ancient origins in our non-human primate relatives."
Commenting on the study, Dr Sam Wilson of the MRC - University of Glasgow Centre for Virus Research in Glasgow, said: "This kind of research helps us understand how the virus works.
"The hope is that one day this will translate into therapy."
The origins of HIV can be traced back millions rather than tens of thousands of years, research suggests.