A primary infection by a parasite may indicate a higher risk of being reinfected in the near future (since infection may indicate that enemies are becoming more abundant). Acquired immunity does not exist in invertebrates despite the fact that they also face increased risks of reinfection following primary exposure. However, when subjected to immune insult, insects can produce immune responses that persist for long enough to provide prophylaxis. Because these immune responses are costly, persistence must be maintained through a selective advantage. We tested for the possibility that these long–lasting immune responses provided increased resistance to later infections by experimentally mimicking a primary immune insult (pre–challenge) in larvae of the mealworm beetle, Tenebrio molitor, with lipopolysaccharides (LPS) prior to early or late exposure to spores of the entomopathogenic fungus Metarhizium anisopliae. We found that pre–challenged larvae produced a long–lasting antimicrobial response, which provided a survival benefit when the larvae were exposed to fungal infection. These results suggest that the observed response is functionally ‘adaptive’.