Communication between the immune and nervous systems, each of which is able to react rapidly to environmental stimuli, may confer a survival advantage. However, precisely how the nervous system influences the immune response and whether neural modulation of immune function is biologically important are not well understood. Here we report that neuronal exocytosis of neuropeptides from dense core vesicles suppressed the survival of Caenorhabditis elegans and their clearance of infection with the human bacterial pathogen Pseudomonas aeruginosa. This immunomodulatory function was mediated by INS-7, an insulin-like neuropeptide whose induction was associated with Pseudomonas virulence. INS-7 secreted from the nervous system functioned in a non-cell autonomous way to activate the insulin pathway and alter basal and inducible expression of immunity-related genes in intestinal cells.