Fluorine is one of the most interesting elements for nuclear and stellar astrophysics 1,2. Fluorine abundance was first measured for stars other than the Sun in 1992 1, then for a handful of metal-poor stars 3, which are likely to have formed in the early Universe. The main production sites of fluorine are under debate and include asymptotic giant branch stars, the ν-process in core-collapse supernovae, and Wolf–Rayet stars 4–10. Due to the difference in the mass and lifetime of progenitor stars, high-redshift observations of fluorine can help constrain the mechanism of fluorine production in massive galaxies. Here, we report the detection of HF (signal-to-noise ratio of 8) in absorption in a gravitationally lensed dusty star-forming galaxy at redshift z = 4.4 with N HF/NH2 as high as ~2 × 10 −9, indicating a very quick ramp-up of the chemical enrichment in this high-z galaxy. At z = 4.4, asymptotic giant branch stars of a few solar masses are very unlikely to dominate the enrichment. Instead, we show that Wolf–Rayet stars are required to produce the observed fluorine abundance at this time, with other production mechanisms becoming important at later times. These observations therefore provide an insight into the underlying processes driving the ramp-up phase of chemical enrichment alongside rapid stellar mass assembly in a young massive galaxy.