Measurements of the cross section for the production of top quark pairs in association with a pair of jets from bottom quarks (sigma(t (t) over barb (b) over bar)) and in association with a pair of jets from quarks of any flavor or gluons (sigma(t (t) over bar jj)) and their ratio are presented. The data were collected in proton-proton collisions at a center-of-mass energy of 13 TeV by the CMS experiment at the LHC in 2016 and correspond to an integrated luminosity of 35.9 fb(-1). The measurements are performed in a fiducial phase space and extrapolated to the full phase space, separately for the dilepton and lepton+jets channels, where lepton corresponds to either an electron or a muon. The results of the measurements in the fiducial phase space for the dilepton and lepton+jets channels, respectively, are sigma(t (t) over bar jj) = 2.36 +/- 0.02 (stat)+/- 0.20 (syst) pb and 31.0 +/- 0.2 (stat)+/- 2.9 (syst) pb, and for the cross section ratio 0.017 +/- 0.001 (stat)+/- 0.001 (syst) and 0.020 +/- 0.001 (stat)+/- 0.001 (syst). The values of sigma(t (t) over barb (b) over bar) are determined from the product of the sigma(t (t) over bar jj) and the cross section ratio, obtaining, respectively, 0.040 +/- 0.002 (stat)+/- 0.005 (syst) pb and 0.62 +/- 0.03 (stat)+/- 0.07 (syst) pb. These measurements are the most precise to date and are consistent, within the uncertainties, with the standard model expectations obtained using a matrix element calculation at next-to-leading order in quantum chromodynamics matched to a parton shower.