The Earth's magnetic heading plays a critical role in numerous applications, including navigation and orientation. The digital compass, which is made with a three-axis magnetometer, has proven to be a very cost-effective tool for providing measurements of the Earth’s magnetic heading. To obtain accurate heading measurements for end users, magnetometer calibration is a vital step to mitigate magnetic measurement distortions caused by hard-iron and soft-iron effects. However, current calibration approaches are often complex and lack performance evaluation at different noise levels. In this paper, we present a novel and efficient calibration algorithm that is conceptually simpler than most existing calibration methods and can be easily implemented. We hypothesized that a low-cost magnetometer as used in a smartphone would achieve 1-degree heading measurement accuracy after calibration using our new algorithm. Before applying this new algorithm to real-world data, we verified its effectiveness through numerical simulations. Our study demonstrated that, as the signal-to-noise ratio (SNR) increased, the root-mean-squared errors (RMSEs) of the estimated calibration parameters approached the corresponding Cramer-Rao bounds (CRBs). Experimental results showed that a magnetic heading accuracy of 1.37 degrees was attained for a smartphone located in Texas, U.S.A., which was more accurate than the heading accuracy obtained using the smartphone’s internal calibrated data. This study suggests that our calibration approach can allow low-cost magnetometers to provide highly accurate heading measurements, offering a cost-effective solution for various applications, including precise navigation.