Noble metal-free electrocatalysts with high activity are highly desirable for the large-scale application of hydrogen evolution reaction (HER). Mo 2 C-based nanomaterials have been proved as a promising alternative to noble metal-based electrocatalysts owing to the Pt-resembled d-band density and optimal intermediates-adsorption properties. However, the aggregation and excessive growth of crystals often occur during their high-temperature synthesis procedure, leading to low catalytic utilization. In this study, the ultrafine Mo 2 C/Mo 2 N heterostructure with large surface and interface confined in the N-doped carbon nanofibers (N-CNFs) was obtained by a melamine-assisted method. The synergistic effect of Mo 2 C/Mo 2 N heterostructure and plenty active sites exposed on the surface of ultrafine nanocrystals improves the electrocatalytic activity. Meanwhile, the N-CNFs ensure fast charge transfer and high structural stability during reactions. Moreover, the in-situ synthesis method strengthens the interfacial coupling interactions between Mo 2 C/Mo 2 N heterostructure and N-CNFs, further enhancing the electronic conductivity and electrocatalytic activity. Owing to these advantages, Mo 2 C/Mo 2 N@N-CNFs exhibit excellent HER performance with a low overpotential of 75 mV at a current density of 10 mV cm −2 in alkaline solution, superior to the single-phased Mo 2 C counterpart and recently reported Mo 2 C/ Mo 2 N-based catalysts. This study highlights a new effective strategy to design efficient electrocatalysts via integrating heterostructure, nanostructure and carbon modification.