Bacteria and lytic viruses (phages) engage in highly dynamic coevolutionary interactions over time, yet we have little idea of how transient selection by phages might shape the future evolutionary trajectories of their host populations. To explore this question, we generated genetically diverse phage-resistant mutants of the bacterium Pseudomonas syringae. We subjected the panel of mutants to prolonged experimental evolution in the absence of phages. Some populations re-evolved phage sensitivity, whereas others acquired compensatory mutations that reduced the costs of resistance without altering resistance levels. To ask whether these outcomes were driven by the initial genetic mechanisms of resistance, we next evolved independent replicates of each individual mutant in the absence of phages. We found a strong signature of historical contingency: some mutations were highly reversible across replicate populations, whereas others were highly entrenched. Through whole-genome sequencing of bacteria over time, we also found that populations with the same resistance gene acquired more parallel sets of mutations than populations with different resistance genes, suggesting that compensatory adaptation is also contingent on how resistance initially evolved. Our study identifies an evolutionary ratchet in bacteria–phage coevolution and may explain previous observations that resistance persists over time in some bacterial populations but is lost in others. We add to a growing body of work describing the key role of phages in the ecological and evolutionary dynamics of their host communities. Beyond this specific trait, our study provides a new insight into the genetic architecture of historical contingency, a crucial component of interpreting and predicting evolution.