The tumor microenvironment (TME) is a complex system that plays an important role in tumor development and progression, but the current knowledge about its effect on bladder cancer (BC) is scarce. In this study, we performed a comprehensive analysis of the relationship between the TME and gene expression profiles to identify prognostic biomarkers for BC. The ESTIMATE algorithm was used to calculate immune and stromal scores of BC patients who were obtained from the Gene Expression Omnibus database. We found that the immune and stromal scores were associated with clinical characteristics and the prognosis of BC patients. Based on these scores, 104 immune-related differentially expressed genes were identified. Further, functional enrichment analysis revealed that these genes were mainly involved in the immune-related biological processes and signaling pathways. Three prognostic genes were then identified and used to establish a risk prediction model using Cox regression analyses. Kaplan-Meier survival analysis showed that the expression levels of COL1A1, COMP, and SERPINE2 significantly correlated with cancer-specific survival and overall survival of BC patients. Additionally, we validated the prognostic values of these genes using two independent cohorts from The Cancer Genome Atlas and Gene Expression Omnibus databases. Finally, the relationships between the three prognostic genes and several immune cells were evaluated using Tumor Immune Estimation Resource, indicating that the expression levels of COL1A1, COMP, and SERPINE2 correlated positively with the tumor infiltration levels of CD4 + T cells and macrophages. In conclusion, the current study comprehensively analyzed the TME and presented immune-related prognostic genes for BC, providing new insights into immunotherapeutic strategies for BC patients.