Genetic variants in the human leukocyte antigen and killer cell immunoglobulin-like receptor regions have been associated with many brain-related diseases, but how they shape brain structure and function remains unclear. To identify the genetic variants in HLA and KIR genes associated with human brain phenotypes, we performed a genetic association study of ∼30 000 European unrelated individuals using brain MRI phenotypes generated by the UK Biobank (UKB). We identified 15 HLA alleles in HLA class I and class II genes significantly associated with at least one brain MRI-based phenotypes (P < 5 × 10−8). These associations converged on several main haplotypes within the HLA. In particular, the human leukocyte antigen alleles within an ancestral haplotype 8.1 were associated with multiple MRI measures, including grey matter volume, cortical thickness (TH) and diffusion MRI (dMRI) metrics. These alleles have been strongly associated with schizophrenia. Additionally, associations were identified between HLA-DRB1*04∼DQA1*03:01∼DQB1*03:02 and isotropic volume fraction of diffusion MRI in multiple white matter tracts. This haplotype has been reported to be associated with Parkinson’s disease. These findings suggest shared genetic associations between brain MRI biomarkers and brain-related diseases. Additionally, we identified 169 associations between the complement component 4 (C4) gene and imaging phenotypes. We found that C4 gene copy number was associated with cortical TH and dMRI metrics. No KIR gene copy numbers were associated with image-derived phenotypes at genome-wide threshold. To address the multiple testing burden in the phenome-wide association study, we performed a multi-trait association analysis using trait-based association test that uses extended Simes procedure and identified MRI image-specific associations. This study contributes to insight into how critical immune genes affect brain-related traits as well as the development of neurological and neuropsychiatric disorders.