Prochlorococcus cyanobacteria are extremely abundant in the oceans, as are the viruses that infect them. How hosts and viruses coexist in nature remains unclear, although the presence of both susceptible and resistant cells may allow this coexistence. Combined whole-genome sequencing and PCR screening technology now enables us to investigate the effect of resistance on genome evolution and the genomic mechanisms behind the long-term coexistence of Prochlorococcus and their viruses. Here we present a genome analysis of 77 substrains selected for resistance to ten viruses, revealing mutations primarily in non-conserved, horizontally transferred genes that localize to a single hypervariable genomic island. Mutations affected viral attachment to the cell surface and imposed a fitness cost to the host, manifested by significantly lower growth rates or a previously unknown mechanism of more rapid infection by other viruses. The mutant genes are generally uncommon in nature yet some carry polymorphisms matching those found experimentally. These data are empirical evidence indicating that viral-attachment genes are preferentially located in genomic islands and that viruses are a selective pressure enhancing the diversity of both island genes and island gene content. This diversity emerges as a genomic mechanism that reduces the effective host population size for infection by a given virus, thus facilitating long-term coexistence between viruses and their hosts in nature.