A key challenge in the application of gut microbial ecology to address issues of human health is a lack of consensus, in terms of microbial features identified, across studies. This is particularly the case for understanding the role of the gut microbiota in shaping local and systemic immunity. The gut microbiota has recently been implicated in efficacy of immunotherapies for cancer. Immune checkpoint inhibitors (ICIs) are antibodies that block immune checkpoint receptors CTLA-4 and PD-1 and restore anti-tumour immunity. These immunotherapies have recently revolutionised treatment of various cancers including melanoma. However, despite increased survival rates, not all patients respond to ICI therapy, and immune activation in normal host tissue can result in severe immune-related adverse events (irAEs), including colitis. At present, it is unclear why response to ICIs varies, and why irAEs only develop in some individuals. Heterogeneity across studies currently limits our understanding of the role the gut microbiota plays in shaping response to treatment and occurrence of adverse events and precludes identification of predictive biomarkers. We aimed to identify microbial ecosystem features linked to response and protection from irAEs during ICI therapy. We profiled pre-treatment faecal microbiota (16S rRNA gene and metagenomic sequencing) and dietary patterns in 103 Australian and Dutch patients treated with ICI for metastatic melanoma and performed an integrated analysis with data from 115 US melanoma patients. In these studies, we observed geographically distinct microbial signatures of response and irAEs. Latent class analysis revealed microbial community ecotypes with different prevalence across the three cohorts. Stratification of patients into these classes enabled identification of consensus biomarkers. Overall, higher response rates to ICI treatment were seen in patients with Ruminococcaceae-dominated microbiomes, which were more diverse, and had greater abundance of methanogenic archaea. Lower response rates were observed in Bacteroidaceae-dominated microbiomes, which were less diverse and associated with elevated C-reactive protein levels, an inflammatory marker. High relative abundance of the key gut microbe Faecalibacterium prausnitzii was identified as an important biomarker of response and protection from irAEs only in patients with Bacteroidaceae-dominated microbiomes, but afforded no benefit in patients with other microbial ecotypes. Poor response was also associated with lower fibre and omega-3 fatty acid consumption. Together, these data provide novel insight into the relevance of gut microbiota signatures and dietary intake in shaping response to ICI. These findings highlight the importance of accounting for microbial community ecology when linking the gut microbiome to human health outcomes.