Four-lepton production in proton-proton collisions, mathrm {p}mathrm {p}rightarrow (mathrm{Z}/ gamma ^*)(mathrm{Z}/gamma ^*) rightarrow 4ell , where ell = mathrm {e} or mu , is studied at a center-of-mass energy of 13,text {TeV} with the CMS detector at the LHC. The data sample corresponds to an integrated luminosity of 35.9,text {fb}^{-1}. The ZZ production cross section, sigma (mathrm {p}mathrm {p}rightarrow mathrm{Z}mathrm{Z}) = 17.2 pm 0.5,text {(stat)} pm 0.7,text {(syst)} pm 0.4,text {(theo)} pm 0.4,text {(lumi)} text { pb} , measured using events with two opposite-sign, same-flavor lepton pairs produced in the mass region 60< m_{ell ^+ell ^-} < 120,text {GeV} , is consistent with standard model predictions. Differential cross sections are measured and are well described by the theoretical predictions. The Z boson branching fraction to four leptons is measured to be mathcal {B}(mathrm{Z}rightarrow 4ell ) = 4.83 _{-0.22}^{+0.23} (stat)_{-0.29}^{+0.32} (syst) pm 0.08 (theo) pm 0.12 (lumi) times 10^{-6} for events with a four-lepton invariant mass in the range 80< m_{4ell } < 100,text {GeV} and a dilepton mass m_{ell ell } > 4,text {GeV} for all opposite-sign, same-flavor lepton pairs. The results agree with standard model predictions. The invariant mass distribution of the four-lepton system is used to set limits on anomalous ZZZ and ZZgamma couplings at 95% confidence level: -0.0012<f_4^mathrm{Z}<0.0010, -0.0010<f_5^mathrm{Z}<0.0013, -0.0012<f_4^{gamma }<0.0013, -0.0012<f_5^{gamma }< 0.0013.