  We study the \'etale cohomology of Hilbert modular varieties, building on the
methods introduced for unitary Shimura varieties in [CS17, CS19]. We obtain the
analogous vanishing theorem: in the "generic" case, the cohomology with torsion
coefficients is concentrated in the middle degree. We also probe the structure
of the cohomology beyond the generic case, obtaining bounds on the range of
degrees where cohomology with torsion coefficients can be non-zero. The proof
is based on the geometric Jacquet--Langlands functoriality established by
Tian--Xiao and avoids trace formula computations for the cohomology of Igusa
varieties. As an application, we show that, when $p$ splits completely in the
totally real field and under certain technical assumptions, the $p$-adic local
Langlands correspondence for $\mathrm{GL}_2(\mathbb{Q}_p)$ occurs in the
completed homology of Hilbert modular varieties.
