Autophagy, a conserved pathway that delivers intracellular materials into lysosomes for degradation, is involved in development, aging, and a variety of diseases. Accumulating evidence demonstrates that autophagy plays a protective role against infectious diseases by diminishing intracellular pathogens, including bacteria, viruses, and parasites. However, the mechanism by which autophagy regulates innate immunity remains largely unknown. Here, we show that autophagy is involved in host defense against a pathogenic bacterium Pseudomonas aeruginosa in the metazoan Caenorhabditis elegans. P. aeruginosa infection induces autophagy via a conserved extracellular signal-regulated kinase (ERK). Intriguingly, impairment of autophagy does not influence the intestinal accumulation of P. aeruginosa, but instead induces intestinal necrosis. Inhibition of necrosis results in the survival of autophagy-deficient worms after P. aeruginosa infection. These findings reveal a previously unidentified role for autophagy in protection against necrosis triggered by pathogenic bacteria in C. elegans and implicate that such a function of autophagy may be conserved through the inflammatory response in diverse organisms.