To understand the molecular basis of how hosts evolve resistance to their parasites, we have investigated the genes that cause variation in the susceptibility of Drosophila melanogaster to viral infection. Using a host-specific pathogen of D. melanogaster called the sigma virus (Rhabdoviridae), we mapped a major-effect polymorphism to a region containing two paralogous genes called CHKov1 and CHKov2. In a panel of inbred fly lines, we found that a transposable element insertion in the protein coding sequence of CHKov1 is associated with increased resistance to infection. Previous research has shown that this insertion results in a truncated messenger RNA that encodes a far shorter protein than the susceptible allele. This resistant allele has rapidly increased in frequency under directional selection and is now the commonest form of the gene in natural populations. Using genetic mapping and site-specific recombination, we identified a third genotype with considerably greater resistance that is currently rare in the wild. In these flies there have been two duplications, resulting in three copies of both the truncated allele of CHKov1 and CHKov2 (one of which is also truncated). Remarkably, the truncated allele of CHKov1 has previously been found to confer resistance to organophosphate insecticides. As estimates of the age of this allele predate the use of insecticides, it is likely that this allele initially functioned as a defence against viruses and fortuitously "pre-adapted" flies to insecticides. These results demonstrate that strong selection by parasites for increased host resistance can result in major genetic changes and rapid shifts in allele frequencies; and, contrary to the prevailing view that resistance to pathogens can be a costly trait to evolve, the pleiotropic effects of these changes can have unexpected benefits.