Construction of reasonable composite architecture to enhance the robustness, alleviate the aggregation, and simultaneously improve the intrinsic poor conductivity is the key to realizing the synthesis of highly efficient noble-metal-free MoSe2-based electrocatalysts for the hydrogen evolution reaction (HER). Herein, space-confined MoSe2 nanosheets grown in an N-doped carbon shell with a hierarchical porous structure (defined as MoSe2/NDC) were designed and fabricated, which acquire improved conductivity and more exposed active sites for hydrogen atom adsorption, exhibiting excellent HER activity both in alkaline and acidic media with a small overpotential of 155/142 mV at a current density of 10 mA cm−2, and a Tafel slope of 68/62 mV dec−1, respectively. More importantly, thanks to the protection of the outermost N-doped carbon layer, the MoSe2/NDC shows excellent durability, with almost no attenuation observed in the time-dependent current density curve at an applied constant overpotential of 155/142 mV up to 24 hours in alkaline or acidic media. The following density functional theory (DFT) calculation results reveal that the excellent HER activity of MoSe2/NDC composites originates from the substantially reduced |ΔGH*| of the intermediate adsorbed hydrogen. The strategy of in situ space-confined-growth combined with the design of a composite hierarchical porous structure provides an efficient solution to fabricate high-performance MoSe2-based pH-universal electrocatalysts for hydrogen production.