Abstract Sediment-hosted gold deposits represent a significant portion of the world’s gold resources. They are characterized by the ubiquitous presence of organic carbon (Corg; or its metamorphosed product, graphite) and the systematic occurrence of invisible gold-bearing arsenian pyrite. Yet the role played by these features on ore formation and the distribution of gold remains a long-standing debate. Here, we attempt to clarify this question via an integrated structural, mineralogical, geochemical, and modeling study of the Shahuindo deposit in northern Peru, representative of an epithermal gold deposit contained in a sedimentary basin. The Shahuindo deposit is hosted within Lower Cretaceous fluvio-deltaic carbon-bearing sandstone, siltstone, and black shale of the Marañón fold-and-thrust belt, where intrusions of Miocene age are also exposed. The emplacement of the auriferous orebodies is constrained by structural (thrust faults, transverse faults) as well as lithological (intrusion contacts, permeable layers, anticlinal hinge in sandstone) features. The defined gold reserves (59 tons; t) are located in the supergene zone in the form of native gold grains. However, a primary mineralization, underneath the oxidized zone, occurs in the form of invisible gold in arsenian pyrite and arsenopyrite. Here, four subsequent pyrite generations were identified—namely, pyI, pyII, pyIII, and pyIV. PyI has mean Au concentrations of 0.3 ppm, contains arsenic that is not detectable, and is enriched in V, Co, Ni, Zn, Ag, and Pb compared to the other pyrite generations. This trace element distribution suggests a diagenetic origin in an anoxic to euxinic sedimentary basin for pyI. Pyrite II and pyIV have comparable mean Au (1.1 and 0.7 ppm, respectively) and As (2.4 and 2.9 wt %, respectively) concentrations and precipitated under conditions evolving from lower (pyrrhotite, chalcopyrite, sphalerite) to higher (enargite, digenite, chalcocite) sulfidation, respectively. The pyIII generation is the major gold event in the primary mineralization, with pyrite reaching 110 ppm Au (mean ~7 ppm) and 5.6 wt % As (mean ~1.8 wt %), while coeval arsenopyrite attains 460 ppm Au. Pyrite III is also enriched in other trace elements such as Se, Ge, Mo, In, Ga, and Bi compared to the other pyrite generations, which is indicative of a magmatic source. Bulk analyses of the surrounding unmineralized rocks show only parts per billion levels of Au and less than 25 ppm As. These data, combined with mass balance considerations, demonstrate that the sedimentary rocks could not be the sole source of gold, as they could only contribute a minor portion of arsenic and sulfur (and iron) to the deposit. Conversely, fluids exsolved from a pluton crystallizing at depth likely provided the great part of the gold endowment. Equilibrium thermodynamics simulations, using geochemical constraints established in this study, demonstrate that interaction between Au-As-S-Fe–bearing fluids and organic carbon-bearing rocks strongly enhanced the fluid ability to transport gold by maximizing its solubility as AuI hydrosulfide complexes via a combined increase of pH and aqueous sulfide concentration. This finding challenges the traditional qualitative view of organic matter acting exclusively as a reducing agent for AuI that should promote gold deposition in its native state (Au0) rather than enhance its solubility in the fluid. Our results have significant implications for the exploration of carbonaceous sedimentary environments. Such settings may provide a very effective mechanism for focusing gold transport. Subsequent scavenging of AuI from solution in a chemically bound form is promoted by the precipitation of arsenian pyrite in permeable structural and lithologic traps, bound by more impermeable units, similar to what occurs in petroleum systems. Our integrated study underlines the important potential of sedimentary Corg-bearing rocks in the formation and distribution of gold and associated metal resources.