A data sample containing top quark pairs produced in association with a boosted Z or Higgs boson is used to search for signs of new physics. The data correspond to an integrated luminosity of 138~\mathrm{fb}^{-1} of proton-proton collisions produced at a center-of-mass energy of 13~\mathrm{TeV} at the LHC and collected by the CMS experiment. Selected collision events contain a single lepton and hadronic jets, including two identified with the decay of bottom quarks, plus an additional large-radius jet with high transverse momentum identified as a Z or Higgs boson candidate decaying to a bottom quark pair. Machine learning techniques are employed to discriminate between or events and events from background processes, which are dominated by \mathrm{t}\bar{\mathrm{t}}+\mbox{jets} production. The signal strengths of boosted and processes are measured, and upper limits are placed on the and differential cross sections as functions of the Z or Higgs boson transverse momentum. In addition, effects of physics beyond the standard model are probed using a framework in which the standard model is considered to be the low-energy effective field theory of a higher-scale theory. Eight possible dimension-six operators are added to the standard model Lagrangian and their corresponding coefficients are constrained via a fit to the data.