Viruses shape microbial community structure and function by altering the fitness of their hosts and by promoting genetic exchange. The complexity of most natural ecosystems has precluded detailed studies of virus-host interactions. We reconstructed virus and host bacterial and archaeal genome sequences from community genomic data from two natural acidophilic biofilms. Viruses were matched to their hosts by analyzing spacer sequences that occur among clustered regularly interspaced short palindromic repeats (CRISPRs) that are a hallmark of virus resistance. Virus population genomic analyses provided evidence that extensive recombination shuffles sequence motifs sufficiently to evade CRISPR spacers. Only the most recently acquired spacers match coexisting viruses, which suggests that community stability is achieved by rapid but compensatory shifts in host resistance levels and virus population structure.