Background Pneumonia risk is influenced by demographics, chronic disease burden, lifestyle, and environmental factors. Despite genome-wide association studies (GWAS), the role of host genetics in pneumonia is still not fully understood, especially in certain subgroups. Methods We conducted a GWAS for pneumonia across FinnGen and Estonian Biobank (EstBB) (91,062 cases and 520,119 controls) populations. Cases with at least one pneumonia episode and subgroups based on the age at first pneumonia diagnosis, recurrent pneumonia, and asthma status were considered. We further estimated genetic correlations and causal relationships between pneumonia and other traits using linkage disequilibrium score regression and Mendelian randomization. Results We identified 13 loci including 5 replicated (PTGER4, TNFRSF1A, CHRNA5, MUC5A, HLA) and 8 novel associations (PTPN22, CRP, APOE, FHIT, MAPKAPK2, TNFSF15, HNF1A, RIN3) mainly harboring genes regulating immunity or lung health associated with pneumonia across subgroups. Interestingly, novel associations included the APOE locus with the ε4 allele having a protective effect on pneumonia. Additionally, we report genetic correlations between pneumonia and 204 other traits, and nine traits potentially causal to pneumonia risk. Conclusions Loci associated with pneumonia harbour genes mainly related to acute inflammation, T cell development, antigen presentation and lung health. The stratified analyses demonstrate differences in genetic risk factors contributing to development of pneumonia in different patient subgroups. In summary, the findings of our study highlight the importance of immunological mechanisms at early life and in adults as well as significance of lifestyle and lung health among the elderly.