Cadmium (Cd) rarely forms Cd-dominant minerals and is hosted mainly in sphalerite. Although Cd incorporation via competition with Fe for Zn sites is widely accepted as being an important substitution mechanism, the causes of variations in sphalerite Cd/Fe ratios remain poorly understood. To address this, we applied in situ chemical analysis, transmission electron microscopy, and machine-learning methods to sphalerite from the world-class Jinding Pb-Zn deposit in China. The sphalerite formed in two stages (Sp1 and Sp2), with each stage having distinct textures and mineral associations. Sp1 is associated with galena, pyrite, marcasite, calcite, and dolomite. It consists of two generations: Sp1a, which is fine-grained and disseminated, and Sp1b, which has crystalline sphalerite cores surrounded by acicular colloform rims along vein margins. In contrast, Sp2 has colloform textures and is associated with abundant celestine, barite, and gypsum. Euhedral Sp1 has lower Cd contents than colloform Sp2 (median Cd contents = 1727 versus 6281 ppm, respectively). In both stages, Cd was incorporated into the sphalerite lattice mainly by substitution for Zn, competing with Fe. The Cd-Fe correlation has a large negative slope for Sp1 (-1.5; low Cd/Fe ratio) and a much higher Cd/Fe ratio for Sp2 (-0.1; high Cd/Fe ratio), indicating a transition from Fe- to Cd-dominated substitution. Furthermore, global sphalerite trace element data show that colloform sphalerite which formed during rapid precipitation is systematically enriched in Pb. Machine-learning-based feature importance analysis identified the Pb content as the most influential predictor of Cd/Fe ratios. Based on previous studies that reported a late-stage fluid mixing event in the Jinding deposit triggered by an influx of meteoric water, our results demonstrate that Cd-Fe partitioning was controlled by fluidmixing-induced supersaturation and subsequent rapid mineral precipitation.