Pig manure and swine wastewater from livestock and poultry contain high levels of nitrogen and phosphorus, which can seriously threaten ecosystems. In this study, biochar derived from pig manure (PMBC) was modified by various magnesium salts to obtain pig manure biochar modified with MgO (MgO-PMBC), Mg(OH)(2) (Mg(OH)(2)-PMBC) and MgCl2 (MgCl2-PMBC), and their capacities of simultaneous adsorption of NH4+-N and PO43–P were investigated. Results showed that the adsorption quantities for NH4+-N and PO43–P decreased in the order: MgO-PMBC >Mg(OH)(2)-PMBC > MgCl2-PMBC > PMBC. When the optimal dosage for MgO-PMBC was determined to be 0.6 g/L and the initial solution pH was set to the ideal value of 7, the maximum adsorption quantities for NH4+-N and PO43–P by MgO-PMBC reached 122.01 mg/g and 206.85 mg/g, respectively, which were 49.8 and 85.5 times of those of the PMBC. The specific surface area and total pore volume of MgO-PMBC were 9.4 times and 4.1 times of the PMBC. Removal rate of PO43–P from swine wastewater was 97.57%, and the concentration of PO43–P from treated swine wastewater was lower than 0.5 mg/L, the primary discharge standard of China’s Comprehensive Wastewater Discharge Standard. The enhanced simultaneous adsorption of NH4+-N and PO43–P by modified PMBC (MgO-PMBC) was ascribed to its greater specific surface area and total pore volume, and the reaction of crystallisation of struvite. Our results demonstrated that pig manure biochar modified by MgO can be used to treat swine wastewater effectively.