Quantitative MRI techniques as well as methods such as blood oxygen level-dependent (BOLD) imaging and in vivo spectroscopy require stringent optimization of magnetic field homogeneity, particularly when using high main magnetic fields. Automated shimming approaches require a method of measuring the main magnetic field, B0, followed by adjusting the currents in resistive shim coils to maximize homogeneity. A robust automated shimming technique using arbitrary mapping acquisition parameters (RASTAMAP) using a 3D multiecho gradient echo sequence that measures B0 with high precision was developed. Inherent compensation and postprocessing methods enable removal of artifacts due to hardware timing errors, gradient propagation delays, gradient amplifier asymmetry, and eddy currents. This allows field maps to be generated for any field of view, bandwidth, resolution, or acquisition orientation without custom tuning of sequence parameters. Field maps of an aqueous phantom show ± 1 Hz variation with altered acquisition orientations and bandwidths. Subsequent fitting of measured shim coil field maps allows calculation of shim currents to produce optimum field homogeneity. Magn Reson Med 51:881–887, 2004. © 2004 Wiley-Liss, Inc.