An analysis of the production of a Higgs boson (H) in association with a top quark-antiquark pair (t (t) over barH) or a single top quark (tH) is presented. The Higgs boson decay into a bottom quark-antiquark pair (H -> b (b) over bar) is targeted, and three different final states of the top quark decays are considered, defined by the number of leptons (electrons or muons) in the event. The analysis utilises proton-proton collision data collected at the CERN LHC with the CMS experiment at root s = 13 TeV in 2016-2018, which correspond to an integrated luminosity of 138 fb(-1). The observed t (t) over barH production rate relative to the standard model expectation is 0.33 +/- 0.26 = 0.33 +/- 0.17(stat) +/- 0.21(syst). Additionally, the t (t) over barH production rate is determined in intervals of Higgs boson transverse momentum. An upper limit at 95% confidence level is set on the tH production rate of 14.6 times the standard model prediction, with an expectation of 19.3(-6.0)(+9.2). Finally, constraints are derived on the strength and structure of the coupling between the Higgs boson and the top quark from simultaneous extraction of the t (t) over barH and tH production rates, and the results are combined with those obtained in other Higgs boson decay channels.