Analysis of the gravity and topography of Mars presently provides our primary quantitative constraints on the internal structure of Mars. We present an inversion of the long‐wavelength (harmonic degree ≤ 10) gravity and topography of Mars for lateral variations of mantle temperature and crustal thickness. Our formulation incorporates both viscous mantle flow (which most prior studies have neglected) and isostatically compensated density anomalies in the crust and lithosphere. Our nominal model has a 150‐km‐thick high‐viscosity surface layer over an isoviscous mantle, with a core radius of 1840 km. It predicts lateral temperature variations of up to a few hundred degrees Kelvin relative to the mean mantle temperature, with high temperature under Tharsis and to a lesser extent under Elysium and cool temperatures elsewhere. Surprisingly, the model predicts crustal thinning beneath Tharsis. If correct, this implies that thinning of the crust by mantle shear stresses dominates over thickening of the crust by volcanism. The major impact basins (Hellas, Argyre, Isidis, Chryse, and Utopia) are regions of crustal thinning, as expected. Utopia is also predicted to be a region of hot mantle, which is hard to reconcile with the surface geology. An alternative model for Utopia treats it as a mascon basin. The Utopia gravity anomaly is consistent with the presence of a 1.2 to 1.6 km thick layer of uncompensated basalt, in good agreement with geologic arguments about the amount of volcanic fill in this area. The mantle thermal structure is the dominant contributor to the observed geoid in our inversion. The mantle also dominates the topography at the longest wavelengths, but shorter wavelengths (harmonic degrees ≥4) are dominated by the crustal structure. Because of the uncertainty about the appropriate numerical values for some of the model's input parameters, we have examined the sensitivity of the model results to the planetary structural model (core radius and core and mantle densities), the mantle's viscosity stratification, and the mean crustal thickness. The model results are insensitive to the specific thickness or viscosity contrast of the high‐viscosity surface layer and to the mean crustal thickness in the range 25 to 100 km. Models with a large core radius or with an upper mantle low‐viscosity zone require implausibly large lateral variations in mantle temperature.