The production of a top quark-antiquark pair in association with a W boson (tt‾WttW) is measured in proton-proton collisions at a center-of-mass energy of 13 TeV. The analyzed data was recorded by the CMS experiment at the CERN LHC and corresponds to an integrated luminosity of 138 fb−1−1. Events with two or three leptons (electrons and muons) and additional jets are selected. In events with two leptons, a multiclass neural network is used to distinguish between the signal and background processes. Events with three leptons are categorized based on the number of jets and of jets originating from b quark hadronization, and the lepton charges. The inclusive tt‾WttW production cross section in the full phase space is measured to be 868 ± 40(stat) ± 51(syst) fb. The tt‾W+ttW+ and tt‾W−ttW− cross sections are also measured as 553 ± 30(stat) ± 30(syst) and 343 ± 26(stat) ± 25(syst) fb, respectively, and the corresponding ratio of the two cross sections is found to be 1.61±0.15(stat)−0.05+0.07(syst)1.61±0.15(stat)−0.05+0.07(syst). The measured cross sections are larger than but consistent with the standard model predictions within two standard deviations, and represent the most precise measurement of these cross sections to date.[