Molybdenum carbides are promising ceramic materials and catalysts. A new and green method for the controllable preparation of molybdenum carbides was proposed by one-step co-electrolysis of Na2MoO4 and CO2 greenhouse gas in carbonate molten salts. The solubility and decomposition thermodynamics of Na2MoO4 were analyzed. The structure, composition, current efficiency, energy consumption, and extraction ratio of molybdenum carbide were effectively regulated by changing the molten salt composition, electrolytic voltage, temperature, and electrolytic time. It was confirmed that MoC, Mo2C, or dual-phase MoC-Mo2C can be controllably prepared. Molybdenum carbides may be mainly obtained by the thermal reaction between C from CO2 and Mo from Na2MoO4. Molybdenum carbides prepared at 850°C and 4.5 V in Na2CO3-K2CO3-32 wt% Li2CO3-15 wt% Na2MoO4 molten salts showed the best electrocatalytic activity for hydrogen evolution reaction. The work provides an innovative and sustainable strategy to prepare molybdenum carbides and utilize CO2.