The abundances of elements in stars are critical clues to stars’ origins. Observed star-to-star variations in logarithmic abundance within an open star cluster—a gravitationally bound ensemble of stars in the Galactic plane—are typically only about 0.01 to 0.05 over many elements1, 2, 3, 4, 5, 6, 7, 8, 9, which is noticeably smaller than the variation of about 0.06 to 0.3 seen in the interstellar medium from which the stars form10, 11, 12, 13, 14. It is unknown why star clusters are so homogenous, and whether homogeneity should also prevail in regions of lower star formation efficiency that do not produce bound clusters. Here we report simulations that trace the mixing of chemical elements as star-forming clouds assemble and collapse. We show that turbulent mixing during cloud assembly naturally produces a stellar abundance scatter at least five times smaller than that in the gas, which is sufficient to explain the observed chemical homogeneity of stars. Moreover, mixing occurs very early, so that regions with star formation efficiencies of about 10 per cent are nearly as well mixed as those with formation efficiencies of about 50 per cent. This implies that even regions that do not form bound clusters are likely to be well mixed, and improves the prospects of using ‘chemical tagging’ to reconstruct (via their unique chemical signatures, or tags) star clusters whose constituent stars have become unbound from one another and spread across the Galactic disk.