We have developed a gravity-inversion method for simultaneously estimating the 3D basement relief of a sedimentary basin and the parameters defining a presumed parabolic decay of the density contrast with depth in a sedimentary pack, assuming prior knowledge about the basement depth at a few points. The sedimentary pack is approximated by a grid of 3D vertical prisms juxtaposed in both horizontal directions of a right-handed coordinate system. The prisms' thicknesses represent the depths to the basement and are the parameters to be estimated from the gravity data. To estimate the parameters defining the parabolic decay of the density contrast with depth and to produce stable depth-to-basement estimates, we imposed smoothness on the basement depths and proximity between estimated and known depths at boreholes. We applied our method to synthetic data from a simulated complex 3D basement relief with two sedimentary sections having distinct parabolic laws describing the density-contrast variation with depth. The results provide good estimates of the true parameters of the parabolic law of density-contrast decay with depth and of the basement relief. Inverting the gravity data from the onshore and part of the shallow offshore Almada Basin on Brazil's northeastern coast shows good correlation with known structural features.