I develop a method for 3D forward modeling and nonlinear inversion of the total-field magnetic anomaly caused by a uniformly magnetized layer with its top and bottom surfaces represented by a linear combination of 2D Gaussian functions. The solution of the forward problem is found through both analytic and numerical methods of integration to calculate the theoretical magnetic anomaly. The magnetic anomalies computed by the present numerical method compare well with the ones calculated by using an analytic solution. To test the robustness of the algorithm, the inversion is performed with noisy synthetic data. The estimated parameters in the case of a synthetic model were found to deviate only modestly from the true parameters in the presence of noise. The algorithm is used to interpret a dipolar magnetic anomaly of high amplitude attributable to a laccolith of intermediate composition in northern Mexico.