Porphyry and epithermal ore deposits, which are the products of magmatic hydrothermal fluids, are intimately associated with volcanoes in continental and island arcs above subduction zones, but the exact nature of this relationship has remained enigmatic. Although metal deposition is usually thought to occur during the waning stages of volcanism, numerous ore deposits have been demonstrated to be synvolcanic. Here we show how the formation of these deposits is tied to volcanic cycles. We relate the chemical variations in vapors from Merapi volcano, Indonesia, to different stages of its eruptive cycle. The chemical compositions of volcanic vapors from subduction zone volcanoes are then compared globally to those of fluid inclusions from porphyry-epithermal deposits. These data show that adiabatic decompression is the principal control on mineralization. The data also suggest that volcanic and subvolcanic magmatic-hydrothermal systems are under lithostatic pressure during quiescence but decompress rapidly during injections of mafic magma and explosive eruptions. During quiescence, the magma evolves through fractional crystallization and devolatilization, gradually becoming oxidized and enriched in gold and other incompatible metals. Upon the injection of sulfur-rich mafic magmas, subvolcanic intrusions brecciate the overlying rocks, the systems are depressurized, the volcanoes erupt explosively, supercritical fluids unmix into vapor and brine, and base metal sulfides precipitate.