A new criterion for the inversion of gravity data minimizes the volume of the causative body, which is equivalent to maximizing its compactness. The anomalous density distribution is obtained using an iterative technique which is numerically stable and rapidly convergent. The principle can also be adapted to include modeling of gravity anomalies by single-density sources. The method is illustrated by the inversion of noise-free and noisy data generated from a two-dimensional model consisting of a regular array of identical rectangular blocks whose densities can be individually specified. In every case the algorithm successfully recovers the correct density distribution from the data. In the case of noise-contaminated data, a complete separation of the noise from the signal is achieved. The effectiveness of the method is demonstrated by the inversion of published gravity data.--Modified journal abstract.