Forecasting elections --- a challenging, high-stakes problem --- is the subject of much uncertainty, subjectivity, and media scrutiny. To shed light on this process, we develop a theory for forecasting elections from the perspective of dynamical systems. Our model borrows ideas from epidemiology, and we use polling data from United States elections to determine its parameters. Surprisingly, our general model performs as well as popular forecasters for the 2012 and 2016 U.S. races for president, Senate, and governor. Although contagion and voting dynamics differ, our work suggests a new approach to elucidate how elections are related across states. It also illustrates the effect of accounting for uncertainty in different ways, provides an illuminating example of data-driven forecasting using dynamical systems, and suggests avenues for future research on political elections. We conclude with our forecast of the senatorial and gubernatorial races on 6~November 2018, which we posted on 5 November.