Survival depends on the selection of behaviors adaptive for the current environment. For example, a mouse should run from a rapidly looming hawk but should freeze if the hawk is coasting across the sky. Although serotonin has been implicated in adaptive behavior, environmental regulation of its functional role remains poorly understood. In mice, we found that stimulation of dorsal raphe serotonin neurons suppressed movement in low- and moderate-threat environments but induced escape behavior in high-threat environments, and that movement-related dorsal raphe serotonin neural dynamics inverted in high-threat environments. Stimulation of dorsal raphe γ-aminobutyric acid (GABA) neurons promoted movement in negative but not positive environments, and movement-related GABA neural dynamics inverted between positive and negative environments. Thus, dorsal raphe circuits switch between distinct operational modes to promote environment-specific adaptive behaviors.