The mechanical oscillation of the heart is fundamental during insect metamorphosis, but it is unclear how morphological changes affect its mechanical dynamics. Here, the micromechanical heartbeat with the monarch chrysalis (Danaus plexippus) during metamorphosis is compared with the structural changes observed through in vivo magnetic resonance imaging (MRI). We employ a novel ultra-sensitive detection approach, optical beam deflection, in order to measure the microscale motions of the pupae during the course of metamorphosis. We observed very distinct mechanical contractions occurring at regular intervals, which we ascribe to the mechanical function of the heart organ. Motion was observed to occur in approximately 15 min bursts of activity with frequencies in the 0.4-1.0 Hz range separated by periods of quiescence during the first 83 per cent of development. In the final stages, the beating was found to be uninterrupted until the adult monarch butterfly emerged. Distinct stages of development were characterized by changes in frequency, amplitude, mechanical quality factor and de/repolarization times of the mechanical pulsing. The MRI revealed that the heart organ remains functionally intact throughout metamorphosis but undergoes morphological changes that are reflected in the mechanical oscillation.