The first measurement of the Higgs boson () width is performed based on evidence for off-shell production in the final state with two bosons decaying into either four charged leptons ( or ), or two charged leptons and two neutrinos. Results are based on data from the CMS experiment at the LHC at a center-of-mass energy of 13~\mathrm{TeV}, corresponding to an integrated luminosity of up to 140~\mathrm{fb}^{-1}. The total size of off-shell production beyond the boson pair production threshold is constrained at confidence to be within the interval times its standard model (SM) expectation. The scenario with no off-shell production is excluded at a confidence level larger than (3.6 standard deviations). The width of the boson is then extracted to be \Gamma_{\mathrm{H}} = 3.2_{-1.7}^{+2.4}~\mathrm{MeV}, in agreement with the SM expectation of 4.1~\mathrm{MeV}. The data are also used to set new constraints on anomalous boson couplings to massive electroweak vector boson pairs.