A search is presented for τ slepton pairs produced in proton–proton collisions at a center-of-mass energy of 13TeV. The search is carried out in events containing two τ leptons in the final state, on the assumption that each τ slepton decays primarily to a τ lepton and a neutralino. Events are considered in which each τ lepton decays to one or more hadrons and a neutrino, or in which one of the τ leptons decays instead to an electron or a muon and two neutrinos. The data, collected with the CMS detector in 2016 and 2017, correspond to an integrated luminosity of 77.2fb-1. The observed data are consistent with the standard model background expectation. The results are used to set 95% confidence level upper limits on the cross section for τ slepton pair production in various models for τ slepton masses between 90 and 200GeV and neutralino masses of 1, 10, and 20GeV. In the case of purely left-handed τ slepton production and decay to a τ lepton and a neutralino with a mass of 1GeV, the strongest limit is obtained for a τ slepton mass of 125GeV at a factor of 1.14 larger than the theoretical cross section.