Pulse-induced transients such as eddy currents can cause problems in measurement techniques where a signal is acquired after an applied preparatory pulse. In ultra-low-field magnetic resonance imaging, performed in magnetic fields typically of the order of 100 μT, the signal-to-noise ratio is enhanced in part by prepolarizing the proton spins with a pulse of much larger magnetic field and in part by detecting the signal with a Superconducting QUantum Interference Device (SQUID). The pulse turn-off, however, can induce large eddy currents in the shielded room, producing an inhomogeneous magnetic-field transient that both seriously distorts the spin dynamics and exceeds the range of the SQUID readout. It is essential to reduce this transient substantially before image acquisition. We introduce dynamical cancellation (DynaCan), a technique in which a precisely designed current waveform is applied to a separate coil during the later part and turn off of the polarizing pulse. This waveform, which bears no resemblance to the polarizing pulse, is designed to drive the eddy currents to zero at the precise moment that the polarizing field becomes zero. We present the theory used to optimize the waveform using a detailed computational model with corrections from measured magnetic-field transients. SQUID-based measurements with DynaCan demonstrate a cancellation of 99%. Dynamical cancellation has the great advantage that, for a given system, the cancellation accuracy can be optimized in software. This technique can be applied to both metal and high-permeability alloy shielded rooms, and even to transients other than eddy currents.