We present results of simulations of the growth of Jupiter and Uranus or Neptune that incorporate the mixing of light gases with denser material entering the planet as solids. Heavy compounds and gas begin to intimately mix when the planet is quite small, and substantial mixing occurs when the planet becomes roughly as massive as Earth, because even incoming silicate planetesimals can then fully vaporize. Nonetheless, until the growing planet is several times as massive as Earth, most accreted ice and rock remain in condensed form as they fall to a region where vaporized ice and rock are well-mixed. Subsequently, planetesimals break up where it is too cool for all the silicates to vaporize, so the silicates continue to sink, but the water remains at higher altitudes. As the planet continues to grow, silicates vaporize farther out. Because the mean molecular weight decreases rapidly outward at many radii, some of the radially inhomogeneities in composition produced during the accretion era are able to survive for billions of years. After 4.57 Gyr, our model Jupiter retains compositional gradients; from the inside outwards one finds: (i) an inner core, dominantly composed of heavy elements; (ii) a density-gradient region, containing the majority of the planet’s heavy elements, where H and He increase in abundance with height, reaching ~90% mass fraction at 30% of Jupiter’s radius, with rocky materials enhanced relative to ices in the lower part of this gradient region and the composition transitioning to ices enhanced relative to rock at higher altitudes; (iv) a large, uniform-composition region (we do not account for He immiscibility), enriched relative to protosolar in heavy elements, especially ices, that contains the bulk of the planet’s mass; and (v) an outer region where condensation of many constituents occurs. This radial compositional profile has heavy elements more broadly distributed within the planet than predicted by classical Jupiter-formation models, but the core is less diluted than suggested by Juno-constrained gravity models. The compositional gradients in the region containing the bulk of the planet’s heavy elements prevent convection, both in our models and the models that fit current gravity, probably resulting in a hot deep interior where much of the energy from the early stages of the planet’s accretion remains trapped.