Mesons comprising a beauty quark and strange quark can oscillate between particle (Bs0) and antiparticle (B¯s0) flavour eigenstates, with a frequency given by the mass difference between heavy and light mass eigenstates, Δms. Here we present a measurement of Δms using Bs0→Ds−π+ decays produced in proton–proton collisions collected with the LHCb detector at the Large Hadron Collider. The oscillation frequency is found to be Δms = 17.7683 ± 0.0051 ± 0.0032 ps−1, where the first uncertainty is statistical and the second is systematic. This measurement improves on the current Δms precision by a factor of two. We combine this result with previous LHCb measurements to determine Δms = 17.7656 ± 0.0057 ps−1, which is the legacy measurement of the original LHCb detector.