Invertebrates lack the specialized immune-memory cells responsible for vertebrate-like acquired immunity. However, there is increasing evidence that past infection by the same pathogen can "prime" the insect immune response, resulting in improved survival upon reinfection. The mechanisms underlying these phenomenological accounts of priming are diverse, and often not completely clear. Here, we investigated the generality, specificity and mechanistic basis of immune priming in the fruit flyDrosophila melanogasterwhen infected with the gram-negative bacterial pathogenProvidencia rettgeri. We further explore the epidemiological consequences of immune priming and find it has the potential to curtail pathogen transmission by reducing pathogen shedding. We find that priming inDrosophilais a long-lasting, pathogen-specific response, occurring in several fly genetic backgrounds and is particularly stronger in male flies. Mechanistically, we find that the enhanced survival of individuals primed with an initial non-lethal bacterial inoculum coincides with a transient decrease in bacterial loads, and that this is likely driven by the IMD-responsive antimicrobial-peptide Diptericin-B in the fat body. Further, we show that while Diptericins are required as the effector of bacterial clearance, it is not solely sufficient for immune priming, and requires regulation by the peptidoglycan recognition proteins PGRP-LB, PGRP-LC and PGRP-LE. We discuss potential explanations for the observed sex differences in priming, and discuss the epidemiological consequences of innate immune priming in invertebrates.