The primary motor cortex (M1) possesses two intermediate layers upstream of the motor-output layer: layer 2/3 (L2/3) and layer 5a (L5a). Although repetitive training often improves motor performance and movement coding by M1 neuronal ensembles, it is unclear how neuronal activities in L2/3 and L5a are reorganized during motor task learning. We conducted two-photon calcium imaging in mouse M1 during 14 training sessions of a self-initiated lever-pull task. In L2/3, the accuracy of neuronal ensemble prediction of lever trajectory remained unchanged globally, with a subset of individual neurons retaining high prediction accuracy throughout the training period. However, in L5a, the ensemble prediction accuracy steadily improved, and one-third of neurons, including subcortical projection neurons, evolved to contribute substantially to ensemble prediction in the late stage of learning. The L2/3 network may represent coordination of signals from other areas throughout learning, whereas L5a may participate in the evolving network representing well-learned movements.