Exclusive capture of carbon dioxide (CO2) from hydrocarbons via adsorptive separation is an important technology in the petrochemical industry, especially for acetylene (C2H2) production. However, the physicochemical similarities between CO2 and C2H2 hamper the development of CO2-preferential sorbents, and CO2 is mainly discerned via C recognition with low efficiency. Here, we report that the ultramicroporous material Al(HCOO)3, ALF, can exclusively capture CO2 from hydrocarbon mixtures, including those containing C2H2 and CH4. ALF shows a remarkable CO2 capacity of 86.2 cm3 g–1 and record-high CO2/C2H2 and CO2/CH4 uptake ratios. The inverse CO2/C2H2 separation and exclusive CO2 capture performance from hydrocarbons are validated via adsorption isotherms and dynamic breakthrough experiments. Notably, the hydrogen-confined pore cavities with appropriate dimensional size provide an ideal pore chemistry to specifically match CO2 via a hydrogen bonding mechanism, with all hydrocarbons rejected. This molecular recognition mechanism is unveiled by in situ Fourier-transform infrared spectroscopy, X-ray diffraction studies, and molecular simulations.