Many (re)emerging infectious diseases in humans arise from pathogen spillover from wildlife or livestock, and accurately predicting pathogen spillover is an important public health goal. In the Americas, yellow fever in humans primarily occurs following spillover from non-human primates via mosquitoes. Predicting yellow fever spillover can improve public health responses through vector control and mass vaccination. Here, we develop and test a mechanistic model of pathogen spillover to predict human risk for yellow fever in Brazil. This environmental risk model, based on the ecology of mosquito vectors and non-human primate hosts, distinguished municipality-months with yellow fever spillover from 2001 to 2016 with high accuracy (AUC = 0.72). Incorporating hypothesized cyclical dynamics of infected primates improved accuracy (AUC = 0.79). Using boosted regression trees to identify gaps in the mechanistic model, we found that important predictors include current and one-month lagged environmental risk, vaccine coverage, population density, temperature and precipitation. More broadly, we show that for a widespread human viral pathogen, the ecological interactions between environment, vectors, reservoir hosts and humans can predict spillover with surprising accuracy, suggesting the potential to improve preventive action to reduce yellow fever spillover and avert onward epidemics in humans. This article is part of the theme issue 'Dynamic and integrative approaches to understanding pathogen spillover'.