The motor cortex is capable of reliably driving complex movements yet exhibits considerable plasticity during motor learning. These observations suggest that the fundamental relationship between motor cortex activity and movement may not be fixed but is instead shaped by learning; however, to what extent and how motor learning shapes this relationship are not fully understood. Here we addressed this issue by using in vivo two-photon calcium imaging to monitor the activity of the same population of hundreds of layer 2/3 neurons while mice learned a forelimb lever-press task over two weeks. Excitatory and inhibitory neurons were identified by transgenic labelling. Inhibitory neuron activity was relatively stable and balanced local excitatory neuron activity on a movement-by-movement basis, whereas excitatory neuron activity showed higher dynamism during the initial phase of learning. The dynamics of excitatory neurons during the initial phase involved the expansion of the movement-related population which explored various activity patterns even during similar movements. This was followed by a refinement into a smaller population exhibiting reproducible spatiotemporal sequences of activity. This pattern of activity associated with the learned movement was unique to expert animals and not observed during similar movements made during the naive phase, and the relationship between neuronal activity and individual movements became more consistent with learning. These changes in population activity coincided with a transient increase in dendritic spine turnover in these neurons. Our results indicate that a novel and reproducible activity-movement relationship develops as a result of motor learning, and we speculate that synaptic plasticity within the motor cortex underlies the emergence of reproducible spatiotemporal activity patterns for learned movements. These results underscore the profound influence of learning on the way that the cortex produces movements.