A measurement is performed of the cross section of top quark pair production in association with a W or Z boson using proton-proton collisions at a center-of-mass energy of 13 TeV at the LHC. The data sample corresponds to an integrated luminosity of 35.9 fb−1, collected by the CMS experiment in 2016. The measurement is performed in the same-sign dilepton, three- and four-lepton final states. The production cross sections are measured to be σ(tt¯W)=0.77−0.11+0.12(stat)−0.12+0.13(syst)pb and σ(tt¯Z)=0.99−0.08+0.09(stat)−0.10+0.12(syst)pb. The expected (observed) signal significance for the t t ¯ W production in same-sign dilepton channel is found to be 4.5 (5.3) standard deviations, while for the t t ¯ Z production in three- and four-lepton channels both the expected and the observed significances are found to be in excess of 5 standard deviations. The results are in agreement with the standard model predictions and are used to constrain the Wilson coefficients for eight dimension-six operators describing new interactions that would modify t t ¯ W and t t ¯ Z production.[Figure not available: see fulltext.].