Due to its inherent electrochemical catalytic activity, molybdenum sulfide (MoS2) is a potential electrocatalyst for hydrogen evolution reaction (HER). However, the limited exposure of its active sites resulting from the easy stacking of nanosheets and inert basal plane hampered its optimal catalytic activity. Herein, we developed a novel facile hydrothermal method to prepare phosphorus-doped MoS2 nanosheets anchored on agar-derived 3D nitrogen-doped porous carbon (P-MoS2/NC). The synthesized P-MoS2/NC electrocatalyst possesses high HER catalytic activity with a low overpotential of 167 mV at 10 mA cm−2 and a small Tafel slope of 45 mV dec−1. The excellent performance is attributed to the unique 3D network carbon structure, which avoids the stacking of the MoS2 sheets resulting in more exposed active sites. Additionally, the P atom introduced on the surface of MoS2 sheets successfully activated the in-plane inertness. This work provides an efficient strategy for designing and preparing high-quality catalysts with enhanced electrocatalytic HER activity.