A search is presented for physics beyond the standard model in final states with two opposite-sign, same-flavor leptons, jets, and missing transverse momentum. The data sample corresponds to an integrated luminosity of 2.3 fb$^{-1}$ of proton-proton collisions at $\sqrt{s}= $ 13 TeV collected with the CMS detector at the LHC in 2015. The analysis uses the invariant mass of the lepton pair, searching for a kinematic edge or a resonant-like excess compatible with the Z boson mass. Both search modes use several event categories in order to increase the sensitivity to new physics. These categories are based on the rapidity of the leptons, the multiplicity of jets and b jets, the scalar sum of jet transverse momenta, and missing transverse momen...