Compulsive actions, defined by maladaptive perseveration and excessive repeat, are shown in various mental diseases. Recent evidence suggests that habit-based decision-making causes such perseveration; however, neural mechanisms for developing habitual, and also excessive, action remain unclear. Here, we developed an original operant overtraining protocol that induces habitual and excessive action in mice. Such compulsive-like action is only observed in about half of overtrained mice, whereas other mice show habitual but not excessive action. During the course of training, training-induced plastic changes in excitatory synaptic inputs, as assessed by AMPA/NMDA ratio, was observed in several regions of the prefrontal cortex. As mice learned the task, an increase in AMPA/NMDA ratio was observed in layer 5 pyramidal neurons of the anterior cingulate cortex (ACC) and lateral orbitofrontal cortex (OFC). When mice were overtrained on a slightly modified task for additional 4 days, the increase in AMPA/NMDA ratio was no longer observed in the ACC of overtrained mice regardless of the excessiveness, whereas the increase was only detected in the lateral OFC of mice showing both habitual and excessive action. Consistently, chemogenetic activation of ACC neurons of overtrained mice restored goal-directed action and inhibition of lateral OFC neurons of compulsive-like mice suppressed excessive response. These results indicate that region-specific changes in excitatory inputs in the prefrontal cortex are critical for the development of compulsivity.