ABSTRACT Optical emission-line ratios are traditionally used to estimate gas metallicities from observed galaxy spectra. While such estimators have been calibrated primarily at low redshift, they are commonly used to interpret observations of high-redshift galaxies, where their applicability may be questioned. We use comprehensive emission-line catalogues of galaxies from the IllustrisTNG simulation including ionization by stars, active galactic nuclei, and shocks to reassess the calibrations of both optical and ultraviolet metallicity estimators at redshifts $0\lesssim z \lesssim 8$. For present-day galaxies, the predicted optical-line calibrations are consistent with previously published ones, while we find different ultraviolet-line ratios, such as He ii λ1640/C iii] λ1908, can provide powerful metallicity diagnostics. At fixed metallicity, most emission-line ratios are predicted to strongly increase or decrease with redshift (with the notable exception of N2O2 = [N ii]λ6584/[O ii] λ3727), primarily because of a change in ionization parameter. The predicted dependence of R3 = [O iii]λ5007/H β and R23 = ([O ii] λ3727 + [O iii]λ5007)/H β, and to a slightly lesser extent R2 = [O ii] λ3727/H β and O32 = [O iii]λ5007/[O ii] λ3727, on O abundance for galaxies at z = 4–8 agrees remarkably well with Te-based measurements in 14 galaxies observed with JWST. This success motivates us to provide new calibrations of optical and ultraviolet metallicity estimators specifically designed for galaxies at z > 4, to guide interpretations of future, high-redshift spectroscopic surveys. We further demonstrate that applying classical z = 0 calibrations to high-redshift galaxies can bias oxygen abundance estimates downward by up to 1 dex, leading to the inference of stronger evolution of the mass–metallicity relation than is actually occurring.