H II regions are ionized nebulae surrounding massive stars. They exhibit a wealth of emission lines that form the basis for estimation of chemical composition. Heavy elements regulate the cooling of interstellar gas, and are essential to the understanding of several phenomena such as nucleosynthesis, star formation and chemical evolution1,2. For over 80 years3, however, a discrepancy exists of a factor of around two between heavy-element abundances derived from collisionally excited lines and those from the weaker recombination lines, which has thrown our absolute abundance determinations into doubt4,5. Here we report observational evidence that there are temperature inhomogeneities within the gas, quantified by t2 (ref. 6). These inhomogeneities affect only highly ionized gas and cause the abundance discrepancy problem. Metallicity determinations based on collisionally excited lines must be revised because these may be severely underestimated, especially in regions of lower metallicity such as those recently observed with the James Webb Space Telescope in high-z galaxies7-9. We present new empirical relations for estimation of temperature and metallicity, critical for a robust interpretation of the chemical composition of the Universe over cosmic time.