When an object is inserted into the strong homogeneous magnetic field of a magnetic resonance magnet, its intrinsic relative susceptibility can cause unwanted local magnetic field inhomogeneities in the space surrounding the object. As is known, this effect can be partially countered by selectively adding material layers with opposing sign in susceptibility to the part. The determination of an optimal magnetic susceptibility distribution is an inverse problem, in which the susceptibility-induced inhomogeneity of the magnetic field inside a region of interest is reduced by redistributing the placement of materials in the design domain. This article proposes an efficient numerical topology optimization method for obtaining an optimal magnetic susceptibility distribution, in particular, for which the induced spatial magnetic field inhomogeneity is minimized. Using a material density function as a design variable, the value of the magnetic field inside a computational domain is determined using a finite element method. The first-order sensitivity of the objective function is calculated using an adjoint equation method. Numerical examples on a variety of design domain geometries illustrate the effectiveness of the optimization method. The method is of specific interest for the design of interventional magnetic resonance devices. It is a particularly useful method if passive shimming of magnetic resonance equipment is aimed for. Magn Reson Med 69:1146–1156, 2013. © 2012 Wiley Periodicals, Inc.