Carbon dioxide (CO2) is produced in fermentation as a byproduct of the metabolic process where yeast or bacteria convert sugars into other compounds.