Growing up on a farm is associated with an asthma-protective effect, but the mechanisms underlying this effect are largely unknown. In the Protection against Allergy: Study in Rural Environments (PASTURE) birth cohort, we modeled maturation using 16S rRNA sequence data of the human gut microbiome in infants from 2 to 12 months of age. The estimated microbiome age (EMA) in 12-month-old infants was associated with previous farm exposure (β = 0.27 (0.12-0.43), P = 0.001, n = 618) and reduced risk of asthma at school age (odds ratio (OR) = 0.72 (0.56-0.93), P = 0.011). EMA mediated the protective farm effect by 19%. In a nested case-control sample (n = 138), we found inverse associations of asthma with the measured level of fecal butyrate (OR = 0.28 (0.09-0.91), P = 0.034), bacterial taxa that predict butyrate production (OR = 0.38 (0.17-0.84), P = 0.017) and the relative abundance of the gene encoding butyryl-coenzyme A (CoA):acetate-CoA-transferase, a major enzyme in butyrate metabolism (OR = 0.43 (0.19-0.97), P = 0.042). The gut microbiome may contribute to asthma protection through metabolites, supporting the concept of a gut-lung axis in humans.