The combustion of fossil fuels produces emissions of the long-lived greenhouse gas carbon dioxide and of short-lived pollutants, including sulfur dioxide, that contribute to the formation of atmospheric aerosols1. Atmospheric aerosols can cool the climate, masking some of the warming effect that results from the emission of greenhouse gases1. However, aerosol particulates are highly toxic when inhaled, leading to millions of premature deaths per year2,3. The phasing out of unabated fossil-fuel combustion will therefore provide health benefits, but will also reduce the extent to which the warming induced by greenhouse gases is masked by aerosols. Because aerosol levels respond much more rapidly to changes in emissions relative to carbon dioxide, large near-term increases in the magnitude and rate of climate warming are predicted in many idealized studies that typically assume an instantaneous removal of all anthropogenic or fossil-fuel-related emissions1,4,5,6,7,8,9. Here we show that more realistic modelling scenarios do not produce a substantial near-term increase in either the magnitude or the rate of warming, and in fact can lead to a decrease in warming rates within two decades of the start of the fossil-fuel phase-out. Accounting for the time required to transform power generation, industry and transportation leads to gradually increasing and largely offsetting climate impacts of carbon dioxide and sulfur dioxide, with the rate of warming further slowed by reductions in fossil-methane emissions. Our results indicate that even the most aggressive plausible transition to a clean-energy society provides benefits for climate change mitigation and air quality at essentially all decadal to centennial timescales.