Agriculture is one of the largest threats to global biodiversity including to birds. But we know little about whether the effects of agriculture on birds are mainly direct through farming operations, or indirect through effects on natural habitats. We sampled birds at 127 sites in eastern Ontario Canada. We used structural equation modelling (SEM) to evaluate the direct and indirect effects of agriculture on species richness of three bird guilds: forest birds, shrub-edge birds, and grassland birds. We found that forest bird richness was driven by the negative indirect effect of cropland via habitat loss. Shrub-edge and grassland bird richness increased with the amount of agriculture, despite negative indirect effects. Our results suggest that management efforts for bird diversity in agricultural landscapes should focus on preserving grassland and forest habitat including forest edges, while managing agricultural land, for instance, by selecting perennial crops and low impact agricultural activities.