Magnetic nanoporous materials represent a new emerging category of magnetic materials for construction of magnetic resonance sensors. In this study, we adopted the metal–organic framework materials, MIL-101(Fe), as the precursor to prepare series nanoporous-carbon-Fe3O4 (NPC-Fe3O4) composites. Results showed that Fe3O4 were uniformly distributed in MIL-101(Fe) and the size of MNP was precisely tuned at different pyrolysis temperatures, conferring the optimal NPC-Fe3O4-450 °C composite with dramatically improved T2 relaxivity. The NPC-Fe3O4-450 °C composite was modified with antibodies and antigens, respectively, for detection of aflatoxin B1 in various food samples with complicated matrix. Range from 0.010 ng mL−1 to 2.0 ng mL−1, extreme low detection limit of 5.0 pg mL−1, and satisfied recoveries were successfully achieved, indicating excellent anti-matrix effect. These findings offer a new dimension to engineer novel magnetic materials with improved relaxivity for simple and easy sensing of food hazards in complicated food matrix without any purification or separation procedures.