Few literatures discussed the relationship of glycemic control and body mass index (BMI) with the risk of pyogenic liver abscess. We conducted a population-based cohort study using participants of a community-based health screening program in Taiwan from 2005 to 2008 (n = 125,865). Information on fasting plasma glucose (FPG), BMI, and other potential risk factors of liver abscess were collected at baseline. Incidence of pyogenic liver abscess was ascertained using inpatient records from the National Health Insurance database. During a median 8.6 years of followed up, 192 incident cases of pyogenic liver abscess were reported. The incidence rate of pyogenic liver abscess was 70.2 and 14.7 per 100,000 in the diabetic and non-diabetic population respectively. In multivariable Cox regression analysis, the adjusted hazard ratio (HR) was 2.18 (95% confidence interval (CI) 1.22–3.90) in patients with diabetes with good glycemic control (FPG ≤ 130 mg/dl) and 3.34 (95% CI 2.37–4.72) in those with poor glycemic control (FPG > 130 mg/dl), when compared with non-diabetics. In the dose–response analysis, the risk of liver abscess increased monotonically with increasing FPG. After adjusting for diabetes and other comorbidities, overweight (25 ≤ BMI < 30) (adjusted HR: 1.43, 95% CI 1.05–1.95) and obese (BMI ≥ 30) (adjusted HR: 1.75, 95% CI 1.09–2.81) populations had a higher risk of liver abscess when compared to people with normal weight.Diabetes, especially poorly controlled disease, and high BMI were associated with higher risk of pyogenic liver abscess. Improving glycemic control and weight reduction may reduce the risk of developing pyogenic liver abscess.