We present a tomographic measurement of the cross-correlation between thermal Sunyaev-Zel'dovich (TSZ) maps from Planck and the Atacama Cosmology Telescope and weak galaxy lensing shears measured during the first three years of observations of the Dark Energy Survey. This correlation is sensitive to the thermal energy in baryons over a wide redshift range and is therefore a powerful probe of astrophysical feedback. We detect the correlation at a statistical significance of 21σ, the highest significance to date. We examine the TSZ maps for potential contaminants, including cosmic infrared background and radio sources, finding that cosmic infrared background has a substantial impact on our measurements and must be taken into account in our analysis. We use the cross-correlation measurements to test different feedback models. In particular, we model the TSZ using several different pressure profile models calibrated against hydrodynamical simulations. Our analysis marginalizes over redshift uncertainties, shear calibration biases, and intrinsic alignment effects. We also marginalize over Ωm and σ8 using Planck or DES priors. We find that the data prefer the model with a low amplitude of the pressure profile at small scales, compatible with a scenario with strong active galactic nuclei feedback and ejection of gas from the inner part of the halos. When using a more flexible model for the shear profile, constraints are weaker, and the data cannot discriminate between different baryonic prescriptions.