Koalas have been running into hard times. They have suffered for years from habitat destruction, dog attacks, automobile accidents. But that’s only the beginning.

They are also plagued by chlamydia and cancers like leukemia and lymphoma, and in researching those problems, scientists have found a natural laboratory in which to study one of the hottest topics in biology: how viruses can insert themselves into an animal’s DNA and sometimes change the course of evolution.

The target of this research is Koala retrovirus, or KoRV, a bit of protein and genetic material in the same family as H.I.V. that began inserting itself into the koala genome about 40,000 years ago and is now passed on from generation to generation, like genes. It is also still passed from animal, as a typical viral infection.

In recent years, scientists have found that the insertion of viruses into the genomes of animals has occurred over and over again. An estimated 8 percent of the human genome is made up of viruses left over from ancient infections, ancient as in millions of years ago, many of them in primate ancestors before human beings existed.

The koala retrovirus is unusual because 40,000 years is the blink of an eye in evolutionary time, and because the process appears to be continuing. A group of scientistsreported in Cell on Thursdaythat they observed a genome immune system fighting to render the virus inactive now that it has established itself in the koala DNA. They also reported that koala retrovirus may have activated other ancient viral DNA. All of this activity stirs the pot of mutation and variation that is the raw material for natural selection.

Koala genetics are a gold mine, said William Theurkauf, a professor in molecular medicine at the University of Massachusetts Medical School and one of the authors of the report. “What they are going through is the process of what’s driven the evolution of every animal on the planet.”

Past viral infections have led to major evolutionary changes, he said. For example: “A gene that is absolutely essential for the placenta was derived from the shell of a virus millions of years ago.” Humans would not exist without that ancient retroviral infection.

Retroviruses are made of RNA, a single strand of genetic information. When they infect a cell, they translate themselves into DNA, the two-stranded molecule that carries all the information for making humans, koalas and other animals. The retroviruses take over the DNA machinery to make more of themselves, which keeps the process going.

That process makes us and other animals sick. AIDS is probably the best known retroviral disease. But when the insertion of a retrovirus occurs in a sperm or an egg cell, the change can become permanent, passed on forever. When retroviruses become part of an animal’s inherited DNA, they are called endogenous and eventually they no longer cause the kind of original infection they once did. But they can still be used by the animal’s genetic machinery for other purposes, like making a placenta.

“It was long thought they were just junk DNA,” said Shawn L. Chavez, a molecular biologist at the Oregon Health and Science University School of Medicine in Portland, who wrote a review of research on endogenous retroviruses in mammals. Now it is clear that some of them have changed the course of evolution. Exactly how is what scientists are trying to find out. “It seems like there’s a new publication every day,” she said.

Consequently, koalas are drawing a lot of attention from scientists who did not start out with an interest in the animal or its conservation. “I’m a fruit fly guy,” Dr. Theurkauf said. He became interested after a report in 2006 by Rachael Tarlinton of the University of Nottingham and other scientists about the invasion of the koala genome by the retrovirus.

Dr. Tarlinton began her career in Australia as a veterinarian with an interest in infectious diseases in wildlife. She became involved in the study of koala genetics because of the problem of chlamydia and because Jon Hanger, an independent researcher, had noticed very high death rates from leukemia and other cancers in koalas kept in zoos. Their research led to the discovery that koala retrovirus was causing some of the cancers and that it was not only infecting the animals but part of their genome.

Dr. Tarlinton and her colleagues established the presence of the retrovirus in koalas in Queensland, but there is another, more southern population of koalas that at first seemed not to have the virus. These koalas also had fewer chlamydia infections. The genetics of the southern population are different because most koalas in that region had been killed for the fur trade by the 1920s. A small number survived by being moved to small islands in the early 20th century.

“From that population, they’ve been reintroduced,” Dr. Tarlinton said. And those koalas have done extraordinarily well, even though they have some genetic problems. There are tens of thousands of them. In some areas they have been killed to keep the population down.

The researchers expected the southern koalas to be less healthy than the northern ones, she said. But the opposite was true.

Still, a deeper look at the southerners’ DNA showed that they weren’t free from the inherited retrovirus as initially thought. The virus was there but it was damaged. The beginning and end of its genetic code were present, but the middle was missing. A report on this work is now in bioRxiv (pronounced bio-archive), an online database for papers that have been written but not yet accepted by peer-reviewed journals.

Dr. Tarlinton and the other researchers plan to submit the research soon. The missing middle could be the key to the health of the southern koalas.

“I think there’s a pretty good chance that having this defective version can be protective,” she said.

An experiment could provide an answer, she said. “We have cell lines that we can get KoRV to grow in. We can insert the defective version of the DNA sequence into the cell line. In essence those cells would then have the damaged retrovirus built in. The researchers could see if the full virus would successfully infect them or be inhibited.

Dr. Theurkauf and his colleagues focused their work on snippets of RNA called piRNAs, which turn off endogenous retroviruses and keep them from replicating and jumping from spot to spot. “It’s a genome immune system,” he said, and is part of how infecting viruses are eventually disabled, so that they don’t keep causing disease.

He and his colleagues found that in koalas there appears to be an initial first-line genome defense involving the piRNA snippets that responds to any virus trying to jump around the genome. Later, a more specific response geared to a particular virus comes into play. This is something they want to test further, by looking at koalas in different populations.

Dr. Theurkauf and his colleagues also discovered other intriguing clues to what happens as viruses become part of an animal’s DNA.

“One thing that we found that is really curious,” Dr. Theurkauf said, is that koalas also have ancient retroviruses that became part of the genome millions of years ago and were presumably deactivated long ago. But at least four of them are just as active as koala retrovirus. They are moving around the genome. “KoRV may be activating these dormant old viruses. It may really stir the pot.”

“It’s evolution in real time,” he said.