The largest galaxies in the universe reside in galaxy clusters. Using sensitive observations of carbon monoxide, we show that the Spiderweb galaxy—a massive galaxy in a distant protocluster—is forming from a large reservoir of molecular gas. Most of this molecular gas lies between the protocluster galaxies and has low velocity dispersion, indicating that it is part of an enriched intergalactic medium. This may constitute the reservoir of gas that fuels the widespread star formation seen in earlier ultraviolet observations of the Spiderweb galaxy. Our results support the notion that giant galaxies in clusters formed from extended regions of recycled gas at high redshift.