Scientists believe a form of HIV probably entered the human population in Africa at least 60 years ago - and that war helped it spread.
War produces conditions for HIV spread
Although HIV is usually spoken of as one virus, in fact it comes in two distinct types, HIV-1 and HIV-2.
HIV-1 came from chimpanzees, and has spread globally; but HIV-2, which came from sootey mangabey monkeys, has remained concentrated in west Africa, where it infects approximately 1% of the population.
A team of international researchers has calculated that HIV-2 crossed to humans sometime between 1890 and 1940 - probably shortly after HIV-1 made the same leap.
The researchers also made a detailed study of how HIV-2 spread within Guinea-Bissau.
They conclude it remained a low-level infection for many years, only spreading widely in the 1960s - a period which coincided with the country's war to gain independence from Portugal.
Portuguese soldiers who had fought in the war were the first Europeans to contract HIV-2.
The scientists say that a number of factors prevalent in wartime - such as mass immunisations with unsterilised needles - could have helped the virus spread rapidly.
Scientists hope that the more they can discover about the way HIV has spread, the better will be the chances of coming up with new ways of combating the virus.
They were able to trace the evolutionary history of HIV-2 by comparing its genetic sequences with those from an ancestral monkey virus.
By estimating the number of genetic mutations in the sequences over time, the scientists were able to track the incidence of HIV-2 and learn when it transferred to humans.
The research is published in the journal Proceedings of the National Academy of Sciences (PNAS).