A search for the electroweak production of charginos and sleptons decaying into final states with two electrons or muons is presented. The analysis is based on 139 fb(-1) of proton-proton collisions recorded by the ATLAS detector at the Large Hadron Collider at v s = 13 TeV. Three R-parity-conserving scenarios where the lightest neutralino is the lightest supersymmetric particle are considered: the production of chargino pairs with decays via eitherW bosons or sleptons, and the direct production of slepton pairs. The analysis is optimised for the first of these scenarios, but the results are also interpreted in the others. No significant deviations from the Standard Model expectations are observed and limits at 95% confidence level are set on the masses of relevant supersymmetric particles in each of the scenarios. For a massless lightest neutralino, masses up to 420 GeV are excluded for the production of the lightest-chargino pairs assuming W-boson-mediated decays and up to 1 TeV for slepton-mediated decays, whereas for slepton-pair production masses up to 700 GeV are excluded assuming three generations of mass-degenerate sleptons.