Anal cancer has increasing incidence and is preceded by high-grade anal intraepithelial neoplasia (HGAIN; AIN2–3). Previously, we identified and validated several methylation markers for accurate detection of anal cancer and HGAIN with cancer risk in HIV-positive (HIV+) men who have sex with men (MSM). This study aimed to evaluate these markers in HIV-negative risk groups. A cross-sectional series of 176 tissue samples of anal cancer, AIN3, AIN2, AIN1 and control biopsies obtained in HIV-negative women and men was tested for six methylation markers (ASCL1, LHX8, SST, WDR17, ZIC1 and ZNF582). Accuracy for detection of AIN3 and cancer (AIN3+) was determined by univariable and multivariable mixed-effect ordinal logistic regression. Methylation levels of all markers increased with increasing severity of disease (P < 0.0001) and were comparable to results in HIV+ MSM. All markers showed high accuracy for AIN3+ detection [area under the curve (AUC): 0.83–0.86]. The optimal marker panel (ASCL1 and ZIC1; AUC = 0.85 for AIN3+) detected 98% of cancers at 79% specificity. In conclusion, DNA methylation markers show a high diagnostic performance for AIN3+ detection in HIV+ and HIV-negative risk groups, justifying broad application of methylation analysis for anal cancer prevention programmes.