  We study the thermodynamics of the relativistic quantum O($N$) model in two
space dimensions. In the vicinity of the zero-temperature quantum critical
point (QCP), the pressure can be written in the scaling form
$P(T)=P(0)+N(T^3/c^2)\calF_N(\Delta/T)$ where $c$ is the velocity of the
excitations at the QCP and $\Delta$ is a characteristic zero-temperature energy
scale. Using both a large-$N$ approach to leading order and the nonperturbative
renormalization group, we compute the universal scaling function $\calF_N$. For
small values of $N$ ($N\lesssim 10$) we find that $\calF_N(x)$ is nonmonotonous
in the quantum critical regime ($|x|\lesssim 1$) with a maximum near $x=0$. The
large-$N$ approach -- if properly interpreted -- is a good approximation both
in the renormalized classical ($x\lesssim -1$) and quantum disordered
($x\gtrsim 1$) regimes, but fails to describe the nonmonotonous behavior of
$\calF_N$ in the quantum critical regime. We discuss the renormalization-group
flows in the various regimes near the QCP and make the connection with the
quantum nonlinear sigma model in the renormalized classical regime. We compute
the Berezinskii-Kosterlitz-Thouless transition temperature in the quantum O(2)
model and find that in the vicinity of the QCP the universal ratio
$\Tkt/\rho_s(0)$ is very close to $\pi/2$, implying that the stiffness
$\rho_s(\Tkt^-)$ at the transition is only slightly reduced with respect to the
zero-temperature stiffness $\rho_s(0)$. Finally, we briefly discuss the
experimental determination of the universal function $\calF_2$ from the
pressure of a Bose gas in an optical lattice near the
superfluid--Mott-insulator transition.
