Leptons with essentially the same properties apart from their mass are grouped into three families (or flavours). The number of leptons of each flavour is conserved in interactions, but this is not imposed by fundamental principles. Since the formulation of the standard model of particle physics, the observation of flavour oscillations among neutrinos has shown that lepton flavour is not conserved in neutrino weak interactions. So far, there has been no experimental evidence that this also occurs in interactions between charged leptons. Such an observation would be a sign of undiscovered particles or a yet unknown type of interaction. Here the ATLAS experiment at the Large Hadron Collider at CERN reports a constraint on lepton-flavour-violating effects in weak interactions, searching for Z-boson decays into a τ lepton and another lepton of different flavour with opposite electric charge. The branching fractions for these decays are measured to be less than 8.1 × 10−6 (eτ) and 9.5 × 10−6 (μτ) at the 95% confidence level using 139 fb−1 of proton–proton collision data at a centre-of-mass energy of s=13TeV and 20.3 fb−1 at s=8TeV. These results supersede the limits from the Large Electron–Positron Collider experiments conducted more than two decades ago.