One of the long-standing challenges in experimental physics is the observation of room-temperature superconductivity1,2. Recently, high-temperature conventional superconductivity in hydrogen-rich materials has been reported in several systems under high pressure3-5. An important discovery leading to room-temperature superconductivity is the pressure-driven disproportionation of hydrogen sulfide (H2S) to H3S, with a confirmed transition temperature of 203 kelvin at 155 gigapascals3,6. Both H2S and CH4 readily mix with hydrogen to form guest-host structures at lower pressures7, and are of comparable size at 4 gigapascals. By introducing methane at low pressures into the H2S + H2 precursor mixture for H3S, molecular exchange is allowed within a large assemblage of van der Waals solids that are hydrogen-rich with H2 inclusions; these guest-host structures become the building blocks of superconducting compounds at extreme conditions. Here we report superconductivity in a photochemically transformed carbonaceous sulfur hydride system, starting from elemental precursors, with a maximum superconducting transition temperature of 287.7 ± 1.2 kelvin (about 15 degrees Celsius) achieved at 267 ± 10 gigapascals. The superconducting state is observed over a broad pressure range in the diamond anvil cell, from 140 to 275 gigapascals, with a sharp upturn in transition temperature above 220 gigapascals. Superconductivity is established by the observation of zero resistance, a magnetic susceptibility of up to 190 gigapascals, and reduction of the transition temperature under an external magnetic field of up to 9 tesla, with an upper critical magnetic field of about 62 tesla according to the Ginzburg-Landau model at zero temperature. The light, quantum nature of hydrogen limits the structural and stoichiometric determination of the system by X-ray scattering techniques, but Raman spectroscopy is used to probe the chemical and structural transformations before metallization. The introduction of chemical tuning within our ternary system could enable the preservation of the properties of room-temperature superconductivity at lower pressures.