This study aimed to ascertain, for the first time, whether serum magnesium (Mg) concentration is affected by the presence of hepatocellular carcinoma (HCC). We retrospectively enrolled consecutive cirrhotic patients with a diagnosis of HCC (n = 130) or without subsequent evidence of HCC during surveillance (n = 161). Serum levels of Mg were significantly (P < 0.001) lower in patients with HCC than in those without (median [interquartile range]: 1.80 [1.62–1.90] mg/dl vs. 1.90 [1.72–2.08] mg/dl). On multivariate logistic regression, low serum Mg was associated with the presence of HCC (OR 0.047, 95% CI 0.015–0.164; P < 0.0001), independently from factors that can influence magnesaemia and HCC development. In a subset of 94 patients with HCC, a linear mixed effects model adjusted for confounders showed that serum Mg at diagnosis of HCC was lower than before diagnosis of the tumor (β = 0.117, 95% CI 0.039–0.194, P = 0.0035) and compared to after locoregional treatment of HCC (β = 0.079, 95% CI 0.010–0.149, P = 0.0259), with two thirds of patients experiencing these changes of serum Mg over time. We hypothesize that most HCCs, like other cancers, may be avid for Mg and behave like a Mg trap, disturbing the body’s Mg balance and resulting in lowering of serum Mg levels.