  Let $\mathcal{G}(N,\frac 1Nt_N)$ be the Erd\H{o}s-R\'enyi graph with
connection probability $\frac 1Nt_N\sim t/N$ as $N\to\infty$ for a fixed
$t\in(0,\infty)$. We derive a large-deviations principle for the empirical
measure of the sizes of all the connected components of $\mathcal{G}(N,\frac
1Nt_N)$, registered according to microscopic sizes (i.e., of finite order),
macroscopic ones (i.e., of order $N$), and mesoscopic ones (everything in
between). The rate function explicitly describes the microscopic and
macroscopic components and the fraction of vertices in components of mesoscopic
sizes. Moreover, it clearly captures the well known phase transition at $t=1$
as part of a comprehensive picture. The proofs rely on elementary combinatorics
and on known estimates and asymptotics for the probability that subgraphs are
connected. We also draw conclusions for the strongly related model of the
multiplicative coalescent, the Marcus--Lushnikov coagulation model with
monodisperse initial condition, and its gelation phase transition.
