A search for pair production of second-generation leptoquarks is performed using proton-proton collision data collected at √s=13 TeV in 2016 with the CMS detector at the CERN LHC, corresponding to an integrated luminosity of 35.9 fb−1. Final states with two muons and two jets, or with one muon, two jets, and missing transverse momentum are considered. Second-generation scalar leptoquarks with masses less than 1530(1285) GeV are excluded for β=1.0(0.5), where β is the branching fraction for the decay of a leptoquark to a charged lepton and a quark. The results of the search are also interpreted as limits on the pair production of long-lived top squarks in an R-parity violating supersymmetry model that has a final state with two muons and two jets. These limits represent the most stringent limits to date on these models.