Background Knowledge of HIV risk factors and reduction strategies is essential for prevention in key populations such as men who have sex with men (MSM) and transgender women (TGW). We evaluated factors associated with HIV-related knowledge among MSM and TGW and the impact of engagement in care at trusted community health centers in Nigeria. Methods The TRUST/RV368 cohort recruited MSM and TGW in Lagos and Abuja, Nigeria via respondent driven sampling. During study visits every three months, participants underwent structured interviews to collect behavioral data, received HIV education, and were provided free condoms and condom compatible lubricants. Five HIV-related knowledge questions were asked at enrollment and repeated after 9 and 15 months. The mean number of correct responses was calculated for each visit with 95% confidence intervals (CIs). Multivariable Poisson regression was used to calculate adjusted risk ratios and CIs for factors associated with answering more knowledge questions correctly. Results From March 2013 to April 2018, 2122 persons assigned male sex at birth were enrolled, including 234 TGW (11.2%). The mean number of correct responses at enrollment was 2.36 (95% CI: 2.31-2.41) and increased to 2.95 (95% CI: 2.86-3.04) and 3.06 (95% CI: 2.97-3.16) after 9 and 15 months in the study, respectively. Among 534 participants who completed all three HIV-related knowledge assessments, mean number of correct responses rose from 2.70 (95% CI: 2.60-2.80) to 3.02 (95% CI: 2.93-3.13) and then 3.06 (95% CI: 2.96-3.16). Factors associated with increased overall HIV-related knowledge included longer duration of study participation, HIV seropositivity, higher education level, and more frequent internet use. Conclusions There was suboptimal HIV-related knowledge among Nigerian MSM and TGW at that improved modestly with engagement in care. These data demonstrate unmet HIV education needs among Nigerian MSM and TGW and provide insights into modalities that could be used to address these needs.