Perovskite tandem solar cells show promising performance, but non-radiative recombination and its progressive worsening with time, especially in the mixed Sn-Pb low-bandgap layer, limit performance and stability. Here we find that mixed Sn-Pb perovskite thin films exhibit a compositional gradient, with an excess of Sn on the surface-and we show this gradient exacerbates oxidation and increases the recombination rate. We find that diamines preferentially chelate Sn atoms, removing them from the film surface and achieving a more balanced Sn:Pb stoichiometry, making the surface of the film resistive to the oxidation of Sn. The process forms an electrically resistive low-dimensional barrier layer, passivating defects and reducing interface recombination. Further improving the homogeneity of the barrier layer using 1,2-diaminopropane results in more uniform distribution and passivation. Tandems achieve a power conversion efficiency of 28.8%. Encapsulated tandems retain 90% of initial efficiency following 1,000 h of operating at the maximum power point under simulated one-sun illumination in air without cooling. The stability of perovskite tandem solar cells is an issue. Li et al. show that diamines improve the compositional homogeneity of a low-bandgap perovskite surface and form a low-dimensional barrier that passivates defects, leading to an operational stability of over 1,000 h.