Purpose The association between exposure to testosterone replacement therapy (TRT) and prostate cancer risk is controversial. The objective was to examine this association through nationwide, population-based registry data. Methods We performed a nested case-control study in the National Prostate Cancer Register of Sweden, which includes all 38,570 prostate cancer cases diagnosed from 2009 to 2012, and 192,838 age-matched men free of prostate cancer. Multivariable conditional logistic regression was used to examine associations between TRT and risk of prostate cancer (overall, favorable, and aggressive). Results Two hundred eighty-four patients with prostate cancer (1%) and 1,378 control cases (1%) filled prescriptions for TRT. In multivariable analysis, no association was found between TRT and overall prostate cancer risk (odds ratio [OR], 1.03; 95% CI, 0.90 to 1.17). However, patients who received TRT had more favorable-risk prostate cancer (OR, 1.35; 95% CI, 1.16 to 1.56) and a lower risk of aggressive prostate cancer (OR, 0.50; 95% CI, 0.37 to 0.67). The increase in favorable-risk prostate cancer was already observed within the first year of TRT (OR, 1.61; 95% CI, 1.10 to 2.34), whereas the lower risk of aggressive disease was observed after > 1 year of TRT (OR, 0.44; 95% CI, 0.32 to 0.61). After adjusting for previous biopsy findings as an indicator of diagnostic activity, TRT remained significantly associated with more favorable-risk prostate cancer and lower risk of aggressive prostate cancer. Conclusion The early increase in favorable-risk prostate cancer among patients who received TRT suggests a detection bias, whereas the decrease in risk of aggressive prostate cancer is a novel finding that warrants further investigation.