Cancers with viral aetiologies can potentially be prevented by antiviral vaccines. Therefore, it is important to understand how viral infections and cancers might be linked. Some cancers frequently carry gammaherpesvirus genomes. However, they generally express the same viral genes as non-transformed cells, and differ mainly in also carrying oncogenic host mutations. Infection, therefore, seems to play a triggering or accessory role in disease. The hit-and-run hypothesis proposes that cumulative host mutations can allow viral genomes to be lost entirely, such that cancers remaining virus-positive represent only a fraction of those to which infection contributes. This would have considerable implications for disease control. However, the hit-and-run hypothesis has so far lacked experimental support. Here, we tested it by using Cre-lox recombination to trigger transforming mutations in virus-infected cells. Thus, 'floxed' oncogene mice were infected with Cre recombinase-positive murid herpesvirus-4 (MuHV-4). The emerging cancers showed the expected genetic changes but, by the time of presentation, almost all lacked viral genomes. Vaccination with a non-persistent MuHV-4 mutant nonetheless conferred complete protection. Equivalent human gammaherpesvirus vaccines could therefore potentially prevent not only viral genome-positive cancers, but possibly also some cancers less suspected of a viral origin because of viral genome loss.