The polymerization of cyanamide and the decomposition of the formed carbon nitride direct the growth of porous MoS2 nanostructures. Highly porous MoS2 nanostructures feature an extremely large specific surface area up to 311 m2 g−1. MoS2 nanostructures manifest an extremely low onset HER overpotential of ∼30 mV and excellent stability.