Diminishing phosphorus resources worldwide requires developing new technologies to recover phosphorus (P) from wastewaters. A lab-scale electrolytic reactor with a magnesium anode was investigated to remove NH4+ and PO43- from synthetic wastewater by producing struvite. The effects of mixing speed, pH, and applied current on struvite yield, NH4+, and PO43- removal efficiencies were first evaluated using a factorial design. Then, the two most significant parameters were further optimized using Central Composite Design (CCD) coupled with Response Surface Methodology (RSM). The struvite was characterized by SEM, XRD, and FT-IR. A 5.7-fold increase in struvite yield was achieved by increasing the applied current from 0.1 to 0.5 A. The three regression equations generated by the CCD/RSM design with applied current and mixing speed as the two independent parameters were highly correlated with the response variables (struvite yield, NH4+ and PO43- removal efficiencies). The desirability analysis showed the best operating condition: current, 0.5 A and mixing speed, 414 rpm, for the reactor system, under which the optimal struvite yield and NH4+ and PO43- removal efficiencies were 4.75 g/L, 93.0%, and 58.4%, respectively. The SEM, XRD, and FT-IR analyses confirmed the high purity and quality of the struvite produced by the electrolytic reactor system.