Climate change is increasing extreme heating events and the potential for disease outbreaks. Whether hosts can adapt to infection with rising temperatures is important for forecasting species persistence. We tested whether warming -- at different host life-stages -- affects the ecological and evolutionary dynamics of resistance in Caenhorabditis elegans infected by a wild bacterial pathogen. We competed genotypes across 10 passages and tracked the spread of resistance in the population. Infection and prolonged warming strongly selected for the resistant genotype. Warming during host development induced plastic defenses against infection, reducing the selective pressure for costly genetic-based resistance. Resistance was lost under ambient temperatures and periodic warming. Selection for resistance was likely weakened at ambient temperatures by the dilution effect, whereby resistant genotype reduced pathogen transmission. Evolutionary dynamics of resistance depend on the balance among pathogen virulence, costs of genetic-based resistance, the dilution effect, and plastic defenses induced by temperature stress.