The superior properties of nanomaterials with a special structure can provide prospects for highly efficient water splitting and lithium storage. Herein, we fabricated a series of peapodlike C@Ni2-x Cox P (x≤1) nanocomposites by an anion-exchange pathway. The experimental results indicated that the HER activity of C@Ni2-x Cox P catalyst is strongly related to the Co/Ni ratio, and the C@NiCoP got the highest HER activity with low onset potential of ∼45 mV, small Tafel slope of ∼43 mV dec(-1) , large exchange current density of 0.21 mA cm(-2) , and high long-term durability (60 h) in 0.5 m H2 SO4 solutions. Equally importantly, as an anode electrode for lithium batteries, this peapodlike C@NiCoP nanocomposite gives excellent charge-discharge properties (e.g., specific capacity of 670 mAh g(-1) at 0.2 A g(-1) after 350 cycles, and a reversible capacity of 405 mAh g(-1) at a high current rate of 10 A g(-1) ). The outstanding performance of C@NiCoP in HER and LIBs could be attributed to the synergistic effect of the rational design of peapodlike nanostructures and the introduction of Co element.