To execute accurate movements, animals must continuously adapt their behavior to changes in their bodies and environments. Animals can learn changes in the relationship between their locomotor commands and the resulting distance moved, then adjust command strength to achieve a desired travel distance. It is largely unknown which circuits implement this form of motor learning, or how. Using whole-brain neuronal imaging and circuit manipulations in larval zebrafish, we discovered that the serotonergic dorsal raphe nucleus (DRN) mediates short-term locomotor learning. Serotonergic DRN neurons respond phasically to swim-induced visual motion, but little to motion that is not self-generated. During prolonged exposure to a given motosensory gain, persistent DRN activity emerges that stores the learned efficacy of motor commands and adapts future locomotor drive for tens of seconds. The DRN's ability to track the effectiveness of motor intent may constitute a computational building block for the broader functions of the serotonergic system. VIDEO ABSTRACT.