Programmed death-1-directed (PD-1-directed) immune checkpoint blockade results in durable antitumor activity in many advanced malignancies. Recent studies suggest that IFN-γ is a critical driver of programmed death ligand-1 (PD-L1) expression in cancer and host cells, and baseline intratumoral T cell infiltration may improve response likelihood to anti-PD-1 therapies, including pembrolizumab. However, whether quantifying T cell-inflamed microenvironment is a useful pan-tumor determinant of PD-1-directed therapy response has not been rigorously evaluated. Here, we analyzed gene expression profiles (GEPs) using RNA from baseline tumor samples of pembrolizumab-treated patients. We identified immune-related signatures correlating with clinical benefit using a learn-and-confirm paradigm based on data from different clinical studies of pembrolizumab, starting with a small pilot of 19 melanoma patients and eventually defining a pan-tumor T cell-inflamed GEP in 220 patients with 9 cancers. Predictive value was independently confirmed and compared with that of PD-L1 immunohistochemistry in 96 patients with head and neck squamous cell carcinoma. The T cell-inflamed GEP contained IFN-γ-responsive genes related to antigen presentation, chemokine expression, cytotoxic activity, and adaptive immune resistance, and these features were necessary, but not always sufficient, for clinical benefit. The T cell-inflamed GEP has been developed into a clinical-grade assay that is currently being evaluated in ongoing pembrolizumab trials.