The detection and compensatory response to the accumulation of unfolded proteins in the endoplasmic reticulum (ER), termed the unfolded protein response (UPR), represents a conserved cellular homeostatic mechanism with important roles in normal development and in the pathogenesis of disease. The IRE1-XBP1/Hac1 pathway is a major branch of the UPR that has been conserved from yeast to human. X-box binding protein 1 (XBP1) is required for the differentiation of the highly secretory plasma cells of the mammalian adaptive immune system, but recent work also points to reciprocal interactions between the UPR and other aspects of immunity and inflammation. We have been studying innate immunity in the nematode Caenorhabditis elegans, having established a principal role for a conserved PMK-1 p38 mitogen-activated protein kinase (MAPK) pathway in mediating resistance to microbial pathogens. Here we show that during C. elegans development, XBP-1 has an essential role in protecting the host during activation of innate immunity. Activation of the PMK-1-mediated response to infection with Pseudomonas aeruginosa induces the XBP-1-dependent UPR. Whereas a loss-of-function xbp-1 mutant develops normally in the presence of relatively non-pathogenic bacteria, infection of the xbp-1 mutant with P. aeruginosa leads to disruption of ER morphology and larval lethality. Unexpectedly, the larval lethality phenotype on pathogenic P. aeruginosa is suppressed by loss of PMK-1-mediated immunity. Furthermore, hyperactivation of PMK-1 causes larval lethality in the xbp-1 mutant even in the absence of pathogenic bacteria. Our data establish innate immunity as a physiologically relevant inducer of ER stress during C. elegans development and indicate that an ancient, conserved role for XBP-1 may be to protect the host organism from the detrimental effects of mounting an innate immune response to microbes.