A simple TeV-scale extension of the Standard Model by scalar leptoquarks recently gained popularity due to the flavor anomalies. But the non-observation of proton decay and charged lepton flavour violation severely constrain the leptoquark interactions, meaning that their ultraviolet (UV) realisation must be rather special. Using a lepton-flavored U(1)X gauge symmetry to restrict the leptoquark interactions, we discover a novel mechanism for rendering the proton exactly stable to all orders in the effective field theory expansion. Introducing a scalar condensate to break the U(1)X in the UV and generate realistic neutrino masses with a type-I seesaw leaves a linearly realised discrete Z9 or Z18 gauge symmetry in the infrared (IR). This symmetry exactly prohibits all ∆B = 1 processes and can easily be adapted to many other new-physics models. Charged lepton flavour violation is forbidden at the renormalisable level, leaving the leptoquarks with approximately preserved muon number. We speculate that U(1)X can emerge from a gauge-flavour unified theory with gauge group SU(12) × SU(2) × SU(2) even deeper in the UV.