There is widespread evidence that petroleum originates from biological processes. Whether hydrocarbons can also be produced from abiogenic precursor molecules under the high-pressure, high-temperature conditions characteristic of the upper mantle remains an open question. It has been proposed that hydrocarbons generated in the upper mantle could be transported through deep faults to shallower regions in the Earth's crust, and contribute to petroleum reserves. Here we use in situ Raman spectroscopy in laser-heated diamond anvil cells to monitor the chemical reactivity of methane and ethane under upper-mantle conditions. We show that when methane is exposed to pressures higher than 2GPa, and to temperatures in the range of 1,000-1,500K, it partially reacts to form saturated hydrocarbons containing 2-4 carbons (ethane, propane and butane) and molecular hydrogen and graphite. Conversely, exposure of ethane to similar conditions results in the production of methane, suggesting that the synthesis of saturated hydrocarbons is reversible. Our results support the suggestion that hydrocarbons heavier than methane can be produced by abiogenic processes in the upper mantle.