This study aimed to investigate the effectiveness and mechanism of biochar and modified magnetic biochar addition in improving the anaerobic digestion (AD) efficiency of swine wastewater under ammonia stress. Two batches of serial experiments were carried out with ammonia levels of 3000, 4500, and 6000 mg/L. The results indicated that a one-time addition of 15 g/L of both types of carbon materials could sustainably optimize the AD performance of swine wastewater at ammonia nitrogen levels of 3000 and 4500 mg/L. In the second batch of experiments, at 4500 mg/L ammonia, groups with C and FeC additions showed 6.5%, 16.2% higher cumulative methane yield and 45.5%, 60.0% greater maximum gas production rates than controls. However, under the ammonia stress condition of 6000 mg/L, the reactor exhibited a mismatch between the carbon material addition and the degree of stress. The maximum methane production rate was intensified only in the first batch, which was 71.8% and 105.1% higher in the C and FeC groups, respectively, than in the control group. The microbiological analysis revealed that biochar optimized the AD performance by enriching the abundance of fermentative bacteria and enhancing the activity of Methanosaeta. In contrast, modified magnetic biochar promoted the enrichment of acetogens and shifted the dominant methanogens from sensitive Methanosaeta to the highly ammonia-tolerant Methanosarcina, thus causing the optimization of AD performance. The findings of this study provided new insights into the mitigation of inhibition and enhancement of efficacy in the anaerobic digestion of swine wastewater.