This paper puts forward a model of the role of phosphorus in crop production, soil phosphorus dynamics and phosphorus loading that integrates the salient economic and ecological features of agricultural phosphorus management. The model accounts for the links between phosphorus fertilization, crop yield, accumulation of soil phosphorus reserves, and phosphorus loading. It can be used to guide precision phosphorus management and erosion control as means to mitigate agricultural loading. Using a parameterization for cereal production in southern Finland, the model is solved numerically to analyze the intertemporally optimal combination of fertilization and erosion control and the associated soil phosphorus development. The optimal fertilizer application rate changes markedly over time in response to changes in the soil phosphorus level. When, for instance, soil phosphorus is initially above the socially optimal steady state level, annually matching phosphorus application to the prevailing soil phosphorus stock produces significantly higher social welfare than using a fixed fertilizer application rate. Erosion control was found to increase welfare only on land that is highly susceptible to erosion.