The invention provides a metal phosphide and heteroatom doped porous carbon composite material as well as preparation and application thereof. The porous carbon composite material is prepared by taking a biomass derived polymer and metal salt as raw materials. The composite material contains heteroatom functional groups and metal phosphide, metal forming the metal phosphide is one or more of Fe, Co, Ni, Cu, Rh, Ru, Mn and Mo, and the particle size of the metal phosphide is 1-80 nm. According to the metal phosphide and heteroatom doped porous carbon composite material, cheap and easily available substance derivatives are used as raw materials; the raw materials provide a carbon source, an oxygen source, a phosphorus source, a nitrogen source or a sulfur source, the metal phosphide and the heteroatom doped porous carbon material are combined under mild conditions, the preparation method is simple, and the obtained composite material has a large specific surface area, can provide a largenumber of sites with reaction activity, and has better performance in the fields of electrocatalysis, lithium-sulfur batteries, sodium batteries, supercapacitors and gas adsorption.