Gamma and beta oscillations are routinely observed in motor-related brain circuits during movement preparation and execution. Entrainment of gamma or beta oscillations via transcranial alternating current stimulation (tACS) over primary motor cortex (M1) has opposite effects on motor performance, suggesting a causal role of these brain rhythms for motor control. However, it is largely unknown which brain mechanisms characterize these changes in motor performance brought about by tACS. In particular, it is unclear whether these effects result from brain activity changes only in the targeted areas or within functionally connected brain circuits. Here we investigated this issue by applying gamma-band and beta-band tACS over M1 in healthy humans during a visuomotor task and concurrent functional magnetic resonance imaging (fMRI). Gamma tACS indeed improved both the velocity and acceleration of visually triggered movements, compared with both beta tACS and sham stimulation. Beta tACS induced a numerical decrease in velocity compared with sham stimulation, but this was not statistically significant. Crucially, gamma tACS induced motor performance enhancements correlated with changed BOLD activity in the stimulated M1. Moreover, we found frequency- and task-specific neural compensatory activity modulations in the dorsomedial prefrontal cortex (dmPFC), suggesting a key regulatory role of this region in motor performance. Connectivity analyses revealed that the dmPFC interacted functionally with M1 and with regions within the executive motor system. These results suggest a role of the dmPFC for motor control and show that tACS-induced behavioral changes not only result from activity modulations underneath the stimulation electrode but also reflect compensatory modulation within connected and functionally related brain networks. More generally, our results illustrate how combined tACS-fMRI can be used to resolve the causal link between cortical rhythms, brain systems, and behavior.