Sulphur-doped, β-zeolite-templated carbons (S-β-ZTCs) were synthesized by chemical vapor co-deposition of hydrogen sulfide (H2S) and acetylene (C2H2) to remove ionic (Hg2+) and organic mercury (Hgorg) from gasoline. In situ doping of sulphur introduced aromatic thiols and thiophenes into the ZTC's framework that removed the mercury by forming Hg–S bonds. Notably, these covalently bonded sulphur groups exhibited better stability than physically deposited elemental sulphur, yielding less than 10% material loss after repeated adsorption-desorption tests. Thanks to these unique chemical properties, the adsorption capacity of S-β-ZTCs for Hg2+ in the gasoline (2660 μg/g) was at least an order of magnitude larger than that of common adsorbents. Moreover, simultaneous adsorption of Hg2+ and Hgorg on S-β-ZTCs proceeded independently when the total mercury concentration was in the range applicable to most natural gas condensate samples. Finally, Grand Canonical Monte Carlo (GCMC) method and Density Functional Theory (DFT) study were used to reveal the adsorption mechanism of ZTCs on Hg2+ and Hgorg. These findings provided a better understanding of the mercury sorption mechanism of S-β-ZTCs and have important practical significance for the clean production of the condensate processing industry.