Objectives: To assess HIV and sexually transmitted infection (STI) prevalence and associated risk factors in men who have sex with men (MSM) in two cities in mainland Tanzania. Methods: We conducted respondent-driven sampling of 300 MSM in Dar es Salaam and Tanga. Results: In Dar es Salaam, 172 (86%) men (median age 23, IQR 21-28) consented to HIV/STI testing, and 30.2% were HIV seropositive. Only five reported a previous positive HIV test: >90% were new HIV detections. 2.5% were syphilis-exposed and none hepatitis B positive, but 21.4% had a curable STI. Over 90% of the gonorrhoea and chlamydia was rectal. In Tanga, 11.1% of MSM were HIV seropositive, 8% hepatitis B positive and 0% were syphilis-exposed, with 4.4% having a curable STI. Predictors of HIV infection were number of MSM known, city, identifying as gay and having first sex with a man. Predictors for STIs were recent unprotected receptive anal intercourse, and number of MSM seen in the last month. 30% of the sample reported that they sold sex. There was no significant association between HIV and STI infection. Conclusions: HIV and STI rates were substantially lower in MSM in a provincial city than in a large metropolis and rates appear to depend on larger numbers of MSM known. Most HIV detected were new cases, and there was a high burden of asymptomatic curable rectal STIs (>1 in 5 MSM). Owing to stigma, MSM may not report homosexuality and thus not have rectal STIs treated. High need for tailored HIV testing and STI screening and treatment of MSM in Tanzania is apparent.