We used machine learning to develop and validate a multivariable algorithm allowing the accurate and early prediction of postoperative hypocalcemia risk. Postoperative hypocalcemia is frequent after total thyroidectomy. An early and accurate individualized prediction of the risk of hypocalcemia could guide the selective prescription of calcium supplementation only to patients most likely to present with hypocalcemia after total thyroidectomy. This retrospective study enrolled all patients undergoing total thyroidectomy in a single referral center between November 2019 and March 2022 (derivation cohort) and April 2022 and September 2022 (validation cohort). The primary study outcome was postoperative hypocalcemia (serum calcium under 80mg/L). Exposures were multiple clinical and biological variables prospectively collected and analyzed with various machine learning methods to develop and validate a multivariable prediction algorithm. Among 610/118 participants in the derivation/validation cohorts, 100 (16.4%)/26 (22%) presented postoperative hypocalcemia. The most accurate prediction algorithm was obtained with random forest and combined intraoperative parathyroid hormone measurements with 3 clinical variables (age, sex, and body mass index) to calculate a postoperative hypocalcemia risk for each patient. After multiple cross-validation, the area under the receiver operative characteristic curve was 0.902 (0.829-0.970) in the derivation cohort, and 0.928 (95% CI: 0.86; 0.97) in the validation cohort. Postoperative hypocalcemia risk values of 7% (low threshold) and 20% (high threshold) had, respectively, a sensitivity of 92%, a negative likelihood ratio of 0.11, a specificity of 90%, and a positive of 7.6 for the prediction of postoperative hypocalcemia. Using machine learning, we developed and validated a simple multivariable model that allowed the accurate prediction of postoperative hypocalcemia. The resulting algorithm could be used at the point of care to guide clinical management after total thyroidectomy.