The aim of the study was to identify factors associated with undiagnosed human immunodeficiency virus (HIV) infection among men who have sex with men (MSM) and male-to-female transgender women in Lima, Peru.We analyzed characteristics of 378 MSM and transgender women recruited from 2 sexually transmitted infection (STI) clinics in Lima, Peru. Descriptive analyses compared: (A) HIV-uninfected, (B) previously undiagnosed HIV-infected, and (C) previously diagnosed HIV-infected participants. Multivariable logistic regression models identified: (1) correlates of previously undiagnosed HIV-infection among participants thought to be HIV-uninfected (B vs A); and (2) correlates of previously undiagnosed HIV-infection among HIV-infected participants (B vs C). Subanalysis identified correlates of frequent HIV testing among participants thought to be HIV-uninfected.Among participants, 31.0% were HIV-infected; of those, 35.0% were previously undiagnosed. Among participants thought to be HIV-uninfected (model 1), recent condomless receptive anal intercourse and last HIV test being over 1-year ago (compared to within the last 6-months) were associated with increased odds of being previously undiagnosed HIV-infected (adjusted odds ratio [aOR] = 2.43, 95% confidence interval [95%CI] = 1.10–5.36; aOR = 2.87, 95%CI = 1.10–7.53, respectively). Among HIV-infected participants (model 2), recent condomless receptive anal intercourse was again associated with previously undiagnosed HIV-infection (aOR = 2.54, 95%CI = 1.04–6.23). Achieving post-secondary education and prior syphilis infection were associated with lower odds of having previously undiagnosed HIV-infection (aOR = 0.35, 95%CI = 0.15–0.81; aOR = 0.32, 95%CI = 0.14–0.75, respectively).Reporting semiannual testing was associated with higher educational attainment, identifying as a transgender woman, or reporting a history of syphilis (aOR = 1.94, 95%CI = 1.11–3.37; aOR = 2.40, 95%CI = 1.23–4.70; aOR = 2.76, 95%CI = 1.62–4.71, respectively). Lower odds of semiannual testing were associated with recent condomless insertive anal intercourse or reporting a moderate or high self-perceived risk of acquiring HIV (aOR = 0.56, 95%CI = 0.33–0.96; aOR = 0.32, 95%CI = 0.18–0.59 and aOR = 0.43, 95%CI = 0.21–0.86, respectively).In our study, undiagnosed HIV-infection was associated with recent condomless receptive anal intercourse, infrequent HIV testing, lower education, and absence of prior syphilis diagnosis. Infrequent HIV testing was associated with lower education, not identifying as transgender, recent condomless insertive anal intercourse, absence of prior syphilis diagnosis, and higher self-perceived risk of HIV. Further efforts to decrease HIV transmission and increase HIV-serostatus awareness should be directed towards effectively promoting condom use and frequent HIV testing, integrated with STI management.