In order to describe the velocity and the anaerobic energy of two runners competing against each other for middle-distance races, we present a mathematical model relying on an optimal control problem for a system of ordinary differential equations. The model is based on energy conservation and on Newton’s second law: resistive forces, propulsive forces and variations in the maximal oxygen uptake are taken into account. The interaction between the runners provides a minimum for staying 1 m behind one’s competitor. We perform numerical simulations and show how a runner can win a race against someone stronger by taking advantage of staying behind, or how they can improve their personal record by running behind someone else. Our simulations show when it is the best time to overtake, depending on the difference between the athletes. Finally, we compare our numerical results with real data from the men’s $1500 m$ finals of different competitions.