An inclusive search for long-lived exotic particles decaying to a pair of muons is presented. The search uses data collected by the CMS experiment at the CERN LHC in proton-proton collisions at s = 13 TeV in 2016 and 2018 and corresponding to an integrated luminosity of 97.6 fb−1. The experimental signature is a pair of oppositely charged muons originating from a common secondary vertex spatially separated from the pp interaction point by distances ranging from several hundred μm to several meters. The results are interpreted in the frameworks of the hidden Abelian Higgs model, in which the Higgs boson decays to a pair of long-lived dark photons ZD, and of a simplified model, in which long-lived particles are produced in decays of an exotic heavy neutral scalar boson. For the hidden Abelian Higgs model with m(ZD) greater than 20 GeV and less than half the mass of the Higgs boson, they provide the best limits to date on the branching fraction of the Higgs boson to dark photons for cτ(ZD) (varying with m(ZD)) between 0.03 and ≈0.5 mm, and above ≈0.5 m. Our results also yield the best constraints on long-lived particles with masses larger than 10 GeV produced in decays of an exotic scalar boson heavier than the Higgs boson and decaying to a pair of muons. [Figure not available: see fulltext.].