1. Mechanical stimulation of the leech, Hirudo medicinalis, elicits withdrawal behavior that has two components: local bending in the segment stimulated and shortening in outlying segments. Local bending is characterized by excitation of longitudinal muscle on one side of the segment and inhibition on the other side. In shortening, all longitudinal muscles are excited. We wished to understand how these distinct motor patterns are produced by a nervous system with segmentally iterated neurons, a configuration that places some limitations on the complexity of connection patterns. 2. We searched for neurons in the segmental nervous system that subserved shortening behavior, expecting to find at least one interneuron in each segment that was involved in shortening behavior exclusively. We found instead that all interneurons involved in shortening are also involved in local bending, and no individual interneuron can completely account for shortening. 3. The motor output caused by individual identified interneurons is not entirely consistent with the shortening motor output pattern. For instance, one interneuron, cell 115, has the same pattern of motor effects from segment to segment, causing excitation of dorsal excitatory motor neurons and inhibition of ventral excitatory motor neurons. These effects would cause dorsal local bending, not shortening, in a few segments. Only one interneuron, cell 125, has motor effects that would cause shortening. 4. Individual interneurons were hyperpolarized while single sensory cells were stimulated, to quantify the contributions of individual interneurons to the observed motor pattern. Interneurons 115 and 125, and the inhibitory motor neuron, cell 1, were found to have significant roles in producing the shortening motor output. 5. A quantitative estimate of the role of each interneuron type showed that the identified interneurons account for most of the excitation of dorsal motor neurons, but for very little of the excitation of ventral motor neurons. This predicts that at least one additional interneuron type remains to be identified, one that would provide excitation to ventral motor neurons in several segments. 6. A back-propagation trained neural network model was constructed to predict the connections of the as yet unidentified interneurons. To match the known properties of interneurons, it was necessary to include a segmental similarity constraint in the training algorithm for segmentally iterated model neurons. The modeled networks predicted that there are at least two kinds of interneurons yet to be found. Also, the modeling showed that interneurons can have input and output patterns that differ very little from segment to segment but yet produce major differences in the motor output.