Magnetic stimulation is a key tool in experimental brain research and several clinical applications. Whereas coil designs and the spatial field properties have been intensively studied in the literature, the temporal dynamics of the field has received little attention. The available pulse shapes are typically determined by the relatively limited capabilities of commercial stimulation devices instead of efficiency or optimality. Furthermore, magnetic stimulation is relatively inefficient with respect to the required energy compared to other neurostimulation techniques. We therefore analyze and optimize the waveform dynamics with a nonlinear model of a mammalian motor axon for the first time, without any pre-definition of waveform candidates. We implemented an unbiased and stable numerical algorithm using variational calculus in combination with a global optimization method. This approach yields very stable results with comprehensible characteristic properties, such as a first phase which reduces ohmic losses in the subsequent pulse phase. We compare the energy loss of these optimal waveforms with the waveforms generated by existing magnetic stimulation devices.