Vanadium phosphate (VPO4) is attracting extensive attention because of its advantages of low cost, stable structure and high theoretical capacity. However, similar to other phosphates, VPO4 suffers from low electrical conductivity and large volume expansion, adversely influencing its electrochemical performance and thus limiting its application as an anode in lithium and sodium ion batteries. Herein, we propose a novel, facile strategy based on the organic-inorganic network of a nanostructured hybrid hydrogel for immobilizing VPO4 in a hierarchically porous carbon framework (3DHP-VPO4@C). VPO4 chemically interacts with the carbon framework via a P-C bond, functioning as a buffer layer to maintain structural stability during charge/discharge cycles. The carbon framework offers an efficient pathway for electron and Li+/Na+ transport to ensure high electronic conductivity of the electrode. The 3DHP-VPO4@C anode exhibits excellent lithium and sodium storage performances, and notably high capacities of 957 mA h g-1 at 0.1 A g-1 and 345.3 mA h g-1 at 5 A g-1 for lithium ion batteries. Full cells consisting of a LiFePO4 cathode and the 3DHP-VPO4@C anode also prove to have superior cycling stability and rate performance for LIBs.