A simultaneous analysis of the B+→K+ℓ+ℓ- and B0→K∗0ℓ+ℓ- decays is performed to test muon-electron universality in two ranges of the square of the dilepton invariant mass, q2. The measurement uses a sample of beauty meson decays produced in proton-proton collisions collected with the LHCb detector between 2011 and 2018, corresponding to an integrated luminosity of 9 fb-1. A sequence of multivariate selections and strict particle identification requirements produce a higher signal purity and a better statistical sensitivity per unit luminosity than previous LHCb lepton universality tests using the same decay modes. Residual backgrounds due to misidentified hadronic decays are studied using data and included in the fit model. Each of the four lepton universality measurements reported is either the first in the given q2 interval or supersedes previous LHCb measurements. The results are compatible with the predictions of the Standard Model.