The ion channel TRPA1 plays a key role in human pain signalling by mediating the detection of reactive electrophiles — noxious chemicals — but its role in invertebrates has been unclear. Now Kang et al. demonstrate that fly and mosquito TRPA1 channels act as molecular sensors of these same chemicals in insect gustatory chemosensory neurons. Further molecular evolution analysis shows that, in contrast to other chemical senses such as gustation or olfaction, reactive electrophile detection represents an ancient sensory modality conserved in molecular detail across some 500 million years of animal evolution. The results should facilitate the design of new repellents against important insect pests affecting agriculture and public health. Reactive electrophiles are noxious chemicals, such as acrolein in cigarette smoke, and are detected by the ion channel TRPA1 in humans. Here it is shown that TRPA1 channels sense these chemicals in the gustatory chemosensory neurons of fruitflies and mosquitoes, too. Further findings show that, unlike with other chemical senses such as smell or taste, the detection of reactive electrophiles relies on an ancient sensor that has been conserved in molecular detail through some 500 million years of evolution. Chemical nociception, the detection of tissue-damaging chemicals, is important for animal survival and causes human pain and inflammation, but its evolutionary origins are largely unknown. Reactive electrophiles are a class of noxious compounds humans find pungent and irritating, such as allyl isothiocyanate (in wasabi) and acrolein (in cigarette smoke)1,2,3. Diverse animals, from insects to humans, find reactive electrophiles aversive1,2,3, but whether this reflects conservation of an ancient sensory modality has been unclear. Here we identify the molecular basis of reactive electrophile detection in flies. We demonstrate that Drosophila TRPA1 (Transient receptor potential A1), the Drosophila melanogaster orthologue of the human irritant sensor, acts in gustatory chemosensors to inhibit reactive electrophile ingestion. We show that fly and mosquito TRPA1 orthologues are molecular sensors of electrophiles, using a mechanism conserved with vertebrate TRPA1s. Phylogenetic analyses indicate that invertebrate and vertebrate TRPA1s share a common ancestor that possessed critical characteristics required for electrophile detection. These findings support emergence of TRPA1-based electrophile detection in a common bilaterian ancestor, with widespread conservation throughout vertebrate and invertebrate evolution. Such conservation contrasts with the evolutionary divergence of canonical olfactory and gustatory receptors and may relate to electrophile toxicity. We propose that human pain perception relies on an ancient chemical sensor conserved across ∼500 million years of animal evolution.