The phasmids are bilateral sensory organs located in the tail of Caenorhabditis elegans and other nematodes. The similar structures of the phasmids and the amphid chemosensory organs in the head have long suggested a chemosensory function for the phasmids. However, the PHA and PHB phasmid neurons are not required for chemotaxis or for dauer formation, and no direct proof of a chemosensory function of the phasmids has been obtained. C. elegans avoids toxic chemicals by reversing its movement, and this behavior is mediated by sensory neurons of the amphid, particularly, the ASH neurons. Here we show that the PHA and PHB phasmid neurons function as chemosensory cells that negatively modulate reversals to repellents. The antagonistic activity of head and tail sensory neurons is integrated to generate appropriate escape behaviors: detection of a repellent by head neurons mediates reversals, which are suppressed by antagonistic inputs from tail neurons. Our results suggest that C. elegans senses repellents by defining a head-to-tail spatial map of the chemical environment.