Checkpoint blockade therapies that reactivate tumour-associated T cells can induce durable tumour control and result in the long-term survival of patients with advanced cancers1. Current predictive biomarkers for therapy response include high levels of intratumour immunological activity, a high tumour mutational burden and specific characteristics of the gut microbiota2,3. Although the role of T cells in antitumour responses has thoroughly been studied, other immune cells remain insufficiently explored. Here we use clinical samples of metastatic melanomas to investigate the role of B cells in antitumour responses, and find that the co-occurrence of tumour-associated CD8+ T cells and CD20+ B cells is associated with improved survival, independently of other clinical variables. Immunofluorescence staining of CXCR5 and CXCL13 in combination with CD20 reveals the formation of tertiary lymphoid structures in these CD8+CD20+ tumours. We derived a gene signature associated with tertiary lymphoid structures, which predicted clinical outcomes in cohorts of patients treated with immune checkpoint blockade. Furthermore, B-cell-rich tumours were accompanied by increased levels of TCF7+ naive and/or memory T cells. This was corroborated by digital spatial-profiling data, in which T cells in tumours without tertiary lymphoid structures had a dysfunctional molecular phenotype. Our results indicate that tertiary lymphoid structures have a key role in the immune microenvironment in melanoma, by conferring distinct T cell phenotypes. Therapeutic strategies to induce the formation of tertiary lymphoid structures should be explored to improve responses to cancer immunotherapy.