Immunosenescence, the age-related decline in immune system function, is a general hallmark of aging. While much is known about the cellular and physiological changes that accompany immunosenescence, we know little about the genetic influences on this phenomenon. In this study we combined age-specific measurements of bacterial clearance ability following infection with whole-genome measurements of the transcriptional response to infection and wounding to identify genes that contribute to the natural variation in immunosenescence, using Drosophila melanogaster as a model system. Twenty inbred lines derived from nature were measured for their ability to clear an Escherichia coli infection at 1 and 4 weeks of age. We used microarrays to simultaneously determine genome-wide expression profiles in infected and wounded flies at each age for 12 of these lines. Lines exhibited significant genetically based variation in bacterial clearance at both ages; however, the genetic basis of this variation changed dramatically with age. Variation in gene expression was significantly correlated with bacterial clearance ability only in the older age group. At 4 weeks of age variation in the expression of 247 genes following infection was associated with genetic variation in bacterial clearance. Functional annotation analyses implicate genes involved in energy metabolism including those in the insulin signaling/TOR pathway as having significant associations with bacterial clearance in older individuals. Given the evolutionary conservation of the genes involved in energy metabolism, our results could have important implications for understanding immunosenescence in other organisms, including humans.