Hepatocellular carcinoma recurrence following liver resection remains a great concern. The study aims to examine the chemopreventive effect of metformin in patients undergoing liver resection for hepatocellular carcinoma from a population-based study. All patients registered as having hepatocellular carcinoma between January 1995 and December 2011 in a nationwide database were retrospectively analysed. Outcomes related to liver resection and the presence of diabetes mellitus were assessed. Prognosis in terms of the use of metformin was further explored, in which only patients in the long-term follow-up starting at 2years were included for analysis. Patients with diabetes mellitus had a significantly poorer outcome than patients without diabetes mellitus. Among diabetes mellitus patients, metformin users had significantly better survival curves in both recurrence-free survival (P<.0001) and overall survival (P<.0001) after liver resection. The hazard ratio of metformin use in hepatocellular carcinoma patients with diabetes mellitus was 0.65 (P<.05, 95% CI=0.60-0.72) for hepatocellular carcinoma recurrence and 0.79 (P<.05, 95% CI=0.72-0.88) for overall survival after liver resection. The risk reduction in hepatocellular carcinoma recurrence after liver resection was significantly associated with a dose/duration dependent of accumulated metformin usage. Diabetes mellitus has an adverse effect on patients with hepatocellular carcinoma regardless of treatment modality. The use of metformin significantly reduces the risk of hepatocellular carcinoma recurrence and improves the overall outcome of patients after liver resection if patients survives the initial 2years. Nonetheless, a prospective controlled study is recommended for validating the metformin use on preventing postoperative hepatocellular carcinoma recurrence.