The associated production of a Higgs boson with a top-quark pair is measured in events characterised by the presence of one or two electrons or muons. The Higgs boson decay into a -quark pair is considered. The analysed data, corresponding to an integrated luminosity of 139 , were collected in proton--proton collisions at the Large Hadron Collider between 2015 and 2018 at a centre-of-mass energy of TeV. The measured signal strength, defined as the ratio of the measured signal yield to that predicted by the Standard Model, is . This result corresponds to an observed (expected) significance of 1.3 (3.0) standard deviations, in agreement with the Standard Model prediction. For the first time, the signal strength is measured differentially in bins of the Higgs boson transverse momentum in the simplified template cross-section framework, including a boosted selection targeting Higgs boson transverse momentum above 300 GeV.