Determination of an exoplanet's mass is a key to understanding its basic properties, including its potential for supporting life. To date, mass constraints for exoplanets are predominantly based on radial velocity (RV) measurements, which are not suited for planets with low masses, large semimajor axes, or those orbiting faint or active stars. Here, we present a method to extract an exoplanet's mass solely from its transmission spectrum. We find good agreement between the mass retrieved for the hot Jupiter HD 189733b from transmission spectroscopy with that from RV measurements. Our method will be able to retrieve the masses of Earth-sized and super-Earth planets using data from future space telescopes that were initially designed for atmospheric characterization.