Clinical outcomes following viral exposures exhibit substantial interindividual variability. Although developing evidence suggests commensal bacteria modulate viral infections, the specific bacteria and mechanisms remain underexplored. Here we define a pathway by which viral infections are inhibited by specific tryptophan-catabolizing bacteria. Using HIV as a model, we bioinformatically associated and experimentally validated several bacterial species that inhibited viral replication. This activity required the aromatic amino acid aminotransferase (ArAT) to metabolize tryptophan into 3-indolelactic acid, which agonizes the aryl hydrocarbon receptor (AhR). Given that AhR regulates multiple viral infections, we found that commensal bacteria also inhibit cytomegalovirus (CMV) in an ArAT-dependent manner. Finally, we confirmed that ArAT is associated with protection against disease outcomes in three distinct human cohorts at-risk for HIV, CMV, or symptomatic COVID-19. Taken together, our results provide mechanistic insight into how commensal bacteria impact viral infections, thereby adding to an emerging field focused on host-commensal-virus interactions.