Results are presented from a search for the pair production of third-generation squarks in proton–proton collision events with two-body decays to bottom or charm quarks and a neutralino, which produces a significant imbalance in the transverse momentum. The search is performed using a sample of proton–proton collision data at View the MathML sources=13TeV recorded by the CMS experiment at the LHC, corresponding to an integrated luminosity of 35.9 fb−1fb−1. No statistically significant excess of events is observed beyond the expected contribution from standard model processes. Exclusion limits are set in the context of simplified models of bottom or top squark pair production. Models with bottom squark masses up to 1220 GeV are excluded at 95% confidence level for light neutralinos, and models with top squark masses of 510 GeV are excluded assuming that the mass splitting between the top squark and the neutralino is small.