Epithelial barrier function is maintained by coordination of cell proliferation and cell loss, whereas barrier dysfunction can lead to disease and organismal death. JNK signalling is a conserved stress signalling pathway activated by bacterial infection and tissue damage, often leading to apoptotic cell death and compensatory cell proliferation. Here we show that the stress inducible transcription factor ATF3 restricts JNK activity in the Drosophila midgut. ATF3 regulates JNK-dependent apoptosis and regeneration through the transcriptional regulation of the JNK antagonist, Raw. Enterocyte-specific ATF3 inactivation increases JNK activity and sensitivity to infection, a phenotype that can be rescued by Raw overexpression or JNK suppression. ATF3 depletion enhances intestinal regeneration triggered by infection, but does not compensate for the loss of enterocytes and ATF3-depleted flies succumb to infection due to intestinal barrier dysfunction. In sum, we provide a mechanism to explain how an ATF3-Raw module controls JNK signalling to maintain normal intestinal barrier function during acute infection.