A search for supersymmetry through the direct pair production of top squarks, with Higgs (H) or Z bosons in the decay chain, is performed using a data sample of proton–proton collisions at View the MathML sources=8 TeV collected in 2012 with the CMS detector at the LHC. The sample corresponds to an integrated luminosity of 19.5 fb−1. The search is performed using a selection of events containing leptons and bottom-quark jets. No evidence for a significant excess of events over the standard model background prediction is observed. The results are interpreted in the context of simplified supersymmetric models with pair production of a heavier top-squark mass eigenstate View the MathML sourcet˜2 decaying to a lighter top-squark mass eigenstate View the MathML sourcet˜1 via either View the MathML sourcet˜2→Ht˜1 or View the MathML sourcet˜2→Zt˜1, followed in both cases by View the MathML sourcet˜1→tχ˜10, where View the MathML sourceχ˜10 is an undetected, stable, lightest supersymmetric particle. The interpretation is performed in the region where the mass difference between the View the MathML sourcet˜1 and View the MathML sourceχ˜10 states is approximately equal to the top-quark mass (View the MathML sourcemt˜1−mχ˜10≃mt), which is not probed by searches for direct View the MathML sourcet˜1 squark pair production. The analysis excludes top squarks with masses View the MathML sourcemt˜2<575 GeV and View the MathML sourcemt˜1<400 GeV at a 95% confidence level.