Mesoporous interconnected carbons with active Fe–P centers hold promise as an alternative to Pt catalysts for oxygen reduction reactions, but their synthesis remains challenging due to the poor control over FexP particle size and carbon microstructure. Herein, we report the successful synthesis of Fe2P nanoparticles encapsulated within heteroatom-doped graphene-like carbons via a simple pyrolysis process starting from a biogenic precursor, which is obtained via microbially mediated iron reduction of polyferric flocs by Shewanella oneidensis MR-1. The strong interaction between bacterial proteins and biogenic vivianite in the precursor plays a significant role in preventing agglomeration of Fe2P nanoparticles and facilitating formation of mesoporous hierarchical carbons with large surface area and high conductivity. The size of Fe2P nanoparticles is tunable in a range from 3 to 80 nm by modulating the properties of the bacteria@vivianite precursor. These properties can vary significantly depending on the molar ratio of electron donors to electron acceptors for acclimation. The resulting Fe2P(3 nm)@BC catalyst derived from the bacteria@vivianite precursor at a molar donor/acceptor ratio of 8:1 exhibits substantially improved activity towards electrocatalytic oxygen reduction as compared to the reference carbon samples. The outstanding oxygen reduction performance of this catalyst is also verified in microbial fuel cells.