Constraints on the lifetime and width of the Higgs boson are obtained from events using data recorded by the CMS experiment during the LHC run 1 with an integrated luminosity of 5.1 and 19.7 fb at a center-of-mass energy of 7 and 8 TeV, respectively. The measurement of the Higgs boson lifetime is derived from its flight distance in the CMS detector with an upper bound of lower than s at the 95% confidence level (CL), corresponding to a lower bound on the width of larger than MeV. The measurement of the width is obtained from an off-shell production technique, generalized to include anomalous couplings of the Higgs boson to two electroweak bosons. From this measurement, a joint constraint is set on the Higgs boson width and a parameter that expresses an anomalous coupling contribution as an on-shell cross-section fraction. The limit on the Higgs boson width is lower than 46 MeV with unconstrained and lower than 26 MeV for at the 95% CL. The constraint lower than at the 95% CL is obtained for the expected standard model Higgs boson width.