Locomotion requires precise control of spinal networks. In tetrapods and bipeds, dynamic regulation of locomotion is simplified by the modular organization of spinal limb circuits, but it is not known whether their predecessors, fish axial circuits, are similarly organized. Here, we demonstrate that the larval zebrafish spinal cord contains distinct, parallel microcircuits for independent control of dorsal and ventral musculature on each side of the body. During normal swimming, dorsal and ventral microcircuits are equally active, but, during postural correction, fish differentially engage these microcircuits to generate torque for self-righting. These findings reveal greater complexity in the axial spinal networks responsible for swimming than previously recognized and suggest an early template of modular organization for more-complex locomotor circuits in later vertebrates.