Alkali-metal-noble-gas comagnetometers operating in the spin exchange relaxation free (SERF) regime have been widely used in frontier science research and navigation technology. Under normal circumstances, the comagnetometer operates at the compensation point so that any interfering external magnetic field is tracked and suppressed by the nuclear spin. This in turn can greatly diminish the comagnetometer's sensitivity to the magnetic field; however, its sensitivity to rotations and to anomalous fields is still maintained. The compensation point is typically adjusted manually, which leads to low accuracy and compensation speed, in addition to only allowing short-term magnetic field stability. In order to account for these problems, we designed a three-axis magnetic field compensation system in real time based on LabVIEW, and employed it to a K-Rb-21Ne comagnetometer. Our study shows that by using a fuzzy-proportional-integral (Fuzzy-PI) controller, the compensation point can be tracked in real time and with higher precision when compared with manually adjusted methods, therefore improving the magnetic field stability and sensitivity of the comagnetometer. In addition, the real-time magnetic compensation system can also be widely used in magnetometers.