In MRI of human brain, the respiratory cycle can induceB0-field fluctuations through motion of the chest and fluctuations in local oxygen concentration. The associated NMR frequency changes can affect the MRI data in various ways and lead to temporal signal fluctuations, and image artifacts such as ghosting and blurring. Since the size of the effect scales with magnetic field strength, artifacts become particularly problematic at fields above 3.0T. Furthermore, the spatial dependence of theB0-field fluctuations complicates their correction. In this work, a new method is presented that allows compensation of field fluctuations by modulating theB0 shims in real time. In this method, a reference scan is acquired to measure the spatial distribution of theB0 effect related to chest motion. During the actual scan, this information is then used, together with chest motion data, to apply compensatingB0 shims in real time. The method can be combined with any type of scan without modifications to the pulse sequence. Real-timeB0 shimming is demonstrated to substantially improve the phase stability of EPI data and the image quality of multishot gradient-echo (GRE) MRI at 7T. Magn Reson Med 57:362–368, 2007. © 2007 Wiley-Liss, Inc.