Tumours evade immune control by creating hostile microenvironments that perturb T cell metabolism and effector function1-4. However, it remains unclear how intra-tumoral T cells integrate and interpret metabolic stress signals. Here we report that ovarian cancer-an aggressive malignancy that is refractory to standard treatments and current immunotherapies5-8-induces endoplasmic reticulum stress and activates the IRE1α-XBP1 arm of the unfolded protein response9,10 in T cells to control their mitochondrial respiration and anti-tumour function. In T cells isolated from specimens collected from patients with ovarian cancer, upregulation of XBP1 was associated with decreased infiltration of T cells into tumours and with reduced IFNG mRNA expression. Malignant ascites fluid obtained from patients with ovarian cancer inhibited glucose uptake and caused N-linked protein glycosylation defects in T cells, which triggered IRE1α-XBP1 activation that suppressed mitochondrial activity and IFNγ production. Mechanistically, induction of XBP1 regulated the abundance of glutamine carriers and thus limited the influx of glutamine that is necessary to sustain mitochondrial respiration in T cells under glucose-deprived conditions. Restoring N-linked protein glycosylation, abrogating IRE1α-XBP1 activation or enforcing expression of glutamine transporters enhanced mitochondrial respiration in human T cells exposed to ovarian cancer ascites. XBP1-deficient T cells in the metastatic ovarian cancer milieu exhibited global transcriptional reprogramming and improved effector capacity. Accordingly, mice that bear ovarian cancer and lack XBP1 selectively in T cells demonstrate superior anti-tumour immunity, delayed malignant progression and increased overall survival. Controlling endoplasmic reticulum stress or targeting IRE1α-XBP1 signalling may help to restore the metabolic fitness and anti-tumour capacity of T cells in cancer hosts.