Recent effective field theory of high-temperature superconductivity (HTS) captures the universal features of HTS and the pseudogap phase and explains the underlying physics as a coexistence of a charge condensate with a condensate of dyons, particles carrying both magnetic and electric charges. Central to this picture are magnetic monopoles emerging in the proximity of the topological quantum superconductor-insulator transition (SIT) that dominates the HTS phase diagram. However, the mechanism responsible for spatially localized electron pairing, characteristic of HTS, remains elusive. Here we show that real-space, localized electron pairing is mediated by magnetic monopoles and occurs well above the superconducting transition temperature Tc. Localized electron pairing promotes the formation of superconducting granules connected by Josephson links. Global superconductivity sets in when these granules form an infinite cluster at Tc, which is estimated to fall in the range from hundred to thousand Kelvins. Our findings pave the way to tailoring materials with elevated superconducting transition temperatures.