Studies have shown that the Zinc finger homeobox 4 (ZFHX4) might be a factor in the prognosis of malignancies. However, little is known about the association between the ZFHX4 mutation and the effectiveness of immune checkpoint inhibitors (ICIs) in non-small cell lung cancer (NSCLC) and melanoma. Three public ICIs-treated NSCLC cohorts were divided into discovery cohort (n=75) and validation cohort (n=62), which were used to evaluate the relationship between ZFHX4 mutation and ICIs effectiveness in NSCLC. Seven ICIs-treated melanoma cohorts (n = 418) were used to analyze the relationship between ZFHX4 mutation and immunotherapy efficacy in melanoma. NSCLC and skin cutaneous melanoma (SKCM) cohorts from The Cancer Genome Atlas (TCGA) were used to investigate underlying mechanism. Patients with ZFHX4 mutant-type (ZFHX4-Mut) showed a superior objective response rate (ORR) (P < 0.01) and longer progression-free survival (PFS) (P < 0.05) than patients with ZFHX4 wild-type (ZFHX4-WT) in NSCLC cohorts. In the melanoma cohorts, patients carrying ZFHX4-Mut had a higher ORR (P = 0.042) and longer overall survival (OS) (P = 0.011). Besides, patients with NSCLC and melanoma harboring ZFHX4-Mut had a higher tumor mutation burden (TMB) (P<0.001) and tumor neoantigen burden (TNB) (P<0.001) than those harboring ZFHX4-WT. ZFHX4 mutation was associated with higher levels of plasma B cells, activated CD4+ memory T cells, and CD8+ T cells. Seven DNA damage repair pathways were significantly enriched in the ZFHX4-Mut group. ZFHX4 mutation could serve as a predicter for the efficacy of ICIs therapy in NSCLC and melanoma.