The upper Oligocene San Rafael intrusive complex (SRIC), located at the southwest margin of the Eastern Cordillera of southeast Peru, is an exceptional case study to investigate the petrogenesis of a large composite granitic pluton associated with the largest known high-grade Sn deposit (>1 Mt. Sn). The granitic rocks are quasi-continuously exposed over more than 1.4 km vertically, from the cupola at surface to deeper levels in the underground mine workings, thus providing access to the upper part of a large pluton. We describe new field relationships and petrographic observations of the main granite varieties of the SRIC, and we report quantitative mineral analyses, whole rock geochemistry (major and trace elements, radiogenic Sr, Nd, and Pb isotopes), and in situ UPb dating and trace element analysis of zircons. The SRIC is dominantly composed of a biotite-cordierite -bearing K-feldspar megacrystic granite, which contains comagmatic enclaves and dismembered dikes of fine-grained and medium-grained granites, and subordinate lamprophyres. While the granitic rocks are widely affected by variable degrees of pervasive hydrothermal alteration, the least altered samples are characterized by moderately fractionated peraluminous S-type compositions, with similar enrichments in incompatible elements (Li, B, Ga, Rb, Sn, Cs, Th, and U), relatively high Zr/Hf and Nb/Ta ratios, and strongly crustal Sr, Nd, and Pb isotopic signatures. In situ UPb dating and trace element analysis of zircons indicate that the granitic magmas crystallized contemporaneously within age uncertainty at 24.02 ± 0.25 Ma (megacrystic granite), 24.17 ± 0.28 Ma (fine-grained granite), and 24.26 ± 0.26 Ma (medium-grained granite) at Ti-in-zircon temperatures from 638° to 840 °C (avg = 759 ± 49 °C). The lamprophyres have high contents of lithophile elements (Li, Rb, Cs, Sn, W) while showing more primitive SrNd isotopic compositions, indicating a metasomatized subcontinental lithospheric mantle source contaminated by crustal assimilation and/or mixing with granitic magmas. Tin contents of the main San Rafael granites are moderate (3–40 ppm; avg. = 13 ppm Sn) and fall in the same range of values as reported for “tin granites” from the Central Andean tin belt. Based on our petrological and geochemical data, we conclude that the SRIC results from multiple injection and mingling/mixing of several types of coexisting felsic and mafic magmas in a shallow-crustal reservoir. The granitic magmas were largely derived from partial melting of metasedimentary protoliths and hybridization with mantle-derived mafic melts, in a regional geodynamic setting dominated by anomalous asthenospheric heat flow beneath the southern Peruvian Altiplano during the Oligocene to Miocene. Based on the moderately fractionated peraluminous character of the SRIC, we conclude that the granitic pluton was a passive host for Sn mineralization and only provided the structural focusing for metal-rich magmatic fluids derived from a deeper part of the granitic magma reservoir. We propose a model in which the injection of high-temperature mafic melts into a more reduced, fractionated granitic magma reservoir triggered late-magmatic oxidation, crystal mush reactivation, and exsolution (second boiling) of metal-rich magmatic fluids. The latter ascended toward the upper part of the crystallized granitic pluton and were focused along subvertical dilational structures, where they cooled down and mixed with downwelling meteoric waters, thus generating the world-class San Rafael Sn (Cu) deposit.