Environmental stresses are thought to be associated with increases in disease suceptibility, attributable to evolutionary trade-offs between the energy demands required to deal with stress vs pathogens. We compared the effects of temperature stress and pathogen exposure on the immune response of a solitary bee, Megachile rotundata. Using an oligonucleotide microarray with 125 genes (375 probes), we determined that both high and low temperatures increased the expression of immune response genes in M. rotundata and reduced levels of a disease called chalkbrood. In the absence of the pathogen, trypsin-like serine and pathogen recognition proteases were most highly expressed at the lowest rearing temperature (20°C), while immune response signalling pathways and melanization were highly expressed at the warmest temperature tested (35°C). In pathogen-exposed bees, immune response genes tended to be most highly expressed at moderate temperatures, where we also saw the greatest infection levels. Temperature stress appears to have activated immunity before the pathogen elicited a response from the host, and this early activity prevented infection under stressful conditions. In this insect, the trade-off in energetic costs associated with stress and infection may be partially avoided by the use of conserved responses that reduce the effects of both.