Upon perception of a noxious stimulus, an organism executes defense mechanisms, such as escape responses. The molecular basis of these mechanisms is poorly understood. In this paper we show that upon exposure to noxious temperature, Caenorhabditis elegans reacts by a withdrawal reflex. To analyze this thermal avoidance behavior, we developed a laser-based assay to quantify the response. The escape reflex can be observed in 98% of the adult animals, but is not executed in animals in diapause. The thermal avoidance response differs significantly from the thermotaxis behavior that is based on the perception of physiological temperature. It involves different neurons and is influenced by mutations in distinct genes. As in mammals, the strength of the thermal avoidance response is increased by application of capsaicin, the pungent ingredient in chili peppers. We find that thermal avoidance is strongly reduced in mutants affecting the neural transmission modulated by glutamate and neuropeptides as well as in mutants affecting the structure and function of sensory neurons. We suggest that the study of this nociceptive behavior in C. elegans can be used to understand the genetic and molecular basis of thermal nociception.