Pathogen expulsion from the gut is an important defense strategy against infection, but little is known about how interaction between the intestinal microbiome and host immunity modulates defecation. In Drosophila melanogaster, dual oxidase (Duox) kills pathogenic microbes by generating the microbicidal reactive oxygen species (ROS), hypochlorous acid (HOCl) in response to bacterially excreted uracil. The physiological function of enzymatically generated HOCl in the gut is, however, unknown aside from its anti-microbial activity. Drosophila TRPA1 is an evolutionarily conserved receptor for reactive chemicals like HOCl, but a role for this molecule in mediating responses to gut microbial content has not been described. Here we identify a molecular mechanism through which bacteria-produced uracil facilitates pathogen-clearing defecation. Ingestion of uracil increases defecation frequency, requiring the Duox pathway and TrpA1. The TrpA1(A) transcript spliced with exon10b (TrpA1(A)10b) that is present in a subset of midgut enteroendocrine cells (EECs) is critical for uracil-dependent defecation. TRPA1(A)10b heterologously expressed in Xenopus oocytes is an excellent HOCl receptor characterized with elevated sensitivity and fast activation kinetics of macroscopic HOCl-evoked currents compared to those of the alternative TRPA1(A)10a isoform. Consistent with TrpA1's role in defecation, uracil-excreting Erwinia carotovora showed higher persistence in TrpA1-deficient guts. Taken together, our results propose that the uracil/Duox pathway promotes bacteria expulsion from the gut through the HOCl-sensitive receptor, TRPA1(A)10b, thereby minimizing the chances that bacteria adapt to survive host defense systems.