Magnetic stimulation is a standard tool in brain research and has found important clinical applications in neurology, psychiatry, and rehabilitation. Whereas coil designs and the spatial field properties have been intensively studied in the literature, the temporal dynamics of the field has received less attention. Typically, the magnetic field waveform is determined by available device circuit topologies rather than by consideration of what is optimal for neural stimulation. This paper analyzes and optimizes the waveform dynamics using a nonlinear model of a mammalian axon. The optimization objective was to minimize the pulse energy loss. The energy loss drives power consumption and heating, which are the dominating limitations of magnetic stimulation. The optimization approach is based on a hybrid global-local method. Different coordinate systems for describing the continuous waveforms in a limited parameter space are defined for numerical stability. The optimization results suggest that there are waveforms with substantially higher efficiency than that of traditional pulse shapes. One class of optimal pulses is analyzed further. Although the coil voltage profile of these waveforms is almost rectangular, the corresponding current shape presents distinctive characteristics, such as a slow low-amplitude first phase which precedes the main pulse and reduces the losses. Representatives of this class of waveforms corresponding to different maximum voltages are linked by a nonlinear transformation. The main phase, however, scales with time only. As with conventional magnetic stimulation pulses, briefer pulses result in lower energy loss but require higher coil voltage than longer pulses.