  For a graph class $\mathcal{F}$, let $ex_{\mathcal{F}}(n)$ denote the maximum
number of edges in a graph in $\mathcal{F}$ on $n$ vertices. We show that for
every proper minor-closed graph class $\mathcal{F}$ the function
$ex_{\mathcal{F}}(n) - \Delta n$ is eventually periodic, where $\Delta =
\lim_{n \to \infty} ex_{\mathcal{F}}(n)/n$ is the limiting density of
$\mathcal{F}$. This confirms a special case of a conjecture by Geelen, Gerards
and Whittle. In particular, the limiting density of every proper minor-closed
graph class is rational, which answers a question of Eppstein.
  As a major step in the proof we show that every proper minor-closed graph
class contains a subclass of bounded pathwidth with the same limiting density,
confirming a conjecture of the second author.
  Finally, we investigate the set of limiting densities of classes of graphs
closed under taking topological minors.
