Exposure to unpredictable and uncontrollable conditions causes animals to perceive stress and change their behavior. It is unclear how the perception of stress modifies the motor components of behavior and which molecular pathways affect the behavioral change. In order to understand how stress affects motor function, we developed an experimental platform that quantifies walking motions in Drosophila. We found that stress induction using electrical shock results in backwards motions of the forelegs at the end of walking strides. These leg retrogressions persisted during repeated stimulation, although they habituated substantially. The motions also continued for several strides after the end of the shock, indicating that stress induces a behavioral aftereffect. Such aftereffect could also be induced by restricting the motion of the flies via wing suspension. Further, the long-term effects could be amplified by combining either immobilization or electric shock with additional stressors. Thus, retrogression is a lingering form of response to a broad range of stressful conditions, which cause the fly to search for a foothold when it faces extreme and unexpected challenges. Mutants in the cAMP signaling pathway enhanced the stress response, indicating that this pathway regulates the behavioral response to stress. Our findings identify the effect of stress on a specific motor component of behavior and define the role of cAMP signaling in this stress response.