  The production of a top quark-antiquark pair in association with a W boson
($\mathrm{t\bar{t}}$W) 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}$. 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 $\mathrm{t\bar{t}}$W production cross section in the full phase space
is measured to be 868 $\pm$ 40 (stat) $\pm$ 51 (syst) fb. The
$\mathrm{t\bar{t}}$W$^+$ and $\mathrm{t\bar{t}}$W$^-$ cross sections are also
measured as 553 $\pm$ 30 (stat) $\pm$ 30 (syst) and 343 $\pm$ 26 (stat) $\pm$
25 (syst) fb, respectively, and the corresponding ratio of the two cross
sections is found to be 1.61 $\pm$ 0.15 (stat) $^{+0.07}_{-0.05}$ (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.
