Men who have sex with men (MSM) are a highly neglected population in the current recommendation of girls-only human papillomavirus (HPV) vaccination programmes in many countries. To better assess the cost effectiveness of HPV vaccination among men requires data on the prevalence of HPV infection in MSM using a community sample, which is still sparse in several regions. We examined the prevalence of and factors associated with anogenital HPV infection among MSM in Taiwan. MSM 20 years of age and older were recruited from the community and social media in Taiwan in 2015-2016 and screened for HPV infection to detect 37 genotypes. MSM were seen at baseline and were/will be seen at 6, 12, 24 and 36 months. Men completed a questionnaire regarding their sexual experiences. Multivariable regression analyses were conducted to identify associated behavioural risk factors using the baseline data. A total of 253 MSM were recruited; 87 % were below 35 years of age. Diagnosis of HIV was reported in 4% of men; just over 20% had three or more anal sex partners in the past year. The prevalence of any tested HPV type was 29.4% at the anal site and 11% at the penile site. One quarter of MSM were infected with any of the 9-valent vaccine HPV types. Anal HPV detection was associated with having three or more receptive anal sex partners in the past year (adjusted odds ratio (aOR)=2.92, 95% CI 1.29 to 6.61) and having older sex partners (aOR=2.51, 95% CI 1.07 to 5.90). Our data provide the base to calculate the reproductive rate for HPV transmission in a low-risk community sample and cost-effectiveness to include men in HPV vaccination policies. Adding evidence from a community sample adds comprehensiveness for future estimates of disease transmission and vaccine effectiveness. © Author(s) (or their employer(s)) 2020. No commercial re-use. See rights and permissions. Published by BMJ.