A search for new physics is carried out in events with at least three electrons or muons in any combination, jets, and missing transverse momentum. Results are based on the sample of proton-proton collision data produced by the LHC at a center-of-mass energy of 13 TeV and collected by the CMS experiment in 2016. The data sample analyzed corresponds to an integrated luminosity of 35.9 fb−1. Events are classified according to the number of b jets, missing transverse momentum, hadronic transverse momentum, and the invariant mass of same-flavor dilepton pairs with opposite charge. No significant excess above the expected standard model background is observed. Exclusion limits at 95% confidence level are computed for four different supersymmetric simplified models with pair production of gluinos or third-generation squarks. In the model with gluino pair production, with subsequent decays into a top quark-antiquark pair and a neutralino, gluinos with masses smaller than 1610 GeV are excluded for a massless lightest supersymmetric particle. In the case of bottom squark pair production, the bottom squark masses are excluded up to 840 GeV for charginos lighter than 200 GeV. For a simplified model of heavy top squark pair production, the t ˜ 2mass is excluded up to 720, 780, or 710 GeV for models with an exclusive t ˜ 2→ t ˜ 1H decay, an exclusive t ˜ 2→ t ˜ 1Z decay, or an equally probable mix of those two decays. In order to provide a simplified version of the analysis for easier interpretation, a small set of aggregate signal regions also has been defined, providing a compromise between simplicity and analysis sensitivity.[Figure not available: see fulltext.].