[proofplan]
We first check that $\mathbb E[X]$ and $\operatorname{Var}(X)$ are well-defined finite quantities under the second-moment hypothesis. The non-negativity follows by writing the variance as the integral of the non-negative [random variable](/page/Random%20Variable) $(X - \mathbb E[X])^2$. For the equality case, we prove that a non-negative integrable random variable has integral zero exactly when it vanishes almost surely, and apply this to $(X - \mathbb E[X])^2$.
[/proofplan]
[step:Verify that the expectation and variance are finite]
Define the real number $m \in \mathbb R$ by
\begin{align*}
m := \mathbb E[X] = \int_\Omega X\, d\mathbb P.
\end{align*}
This is well-defined because, pointwise on $\Omega$,
\begin{align*}
|X| \leq \frac{1 + X^2}{2},
\end{align*}
and hence
\begin{align*}
\int_\Omega |X|\, d\mathbb P \leq \frac{1}{2}\mathbb P(\Omega) + \frac{1}{2}\int_\Omega X^2\, d\mathbb P < \infty.
\end{align*}
Now define the random variable
\begin{align*}
Y: (\Omega, \mathcal F) &\to ([0,\infty), \mathcal B([0,\infty))) \\
\omega &\mapsto (X(\omega) - m)^2.
\end{align*}
Since $X$ is measurable and $t \mapsto (t-m)^2$ is Borel measurable, $Y$ is measurable. Moreover, pointwise,
\begin{align*}
Y = (X-m)^2 \leq 2X^2 + 2m^2.
\end{align*}
Therefore
\begin{align*}
\int_\Omega Y\, d\mathbb P \leq 2\int_\Omega X^2\, d\mathbb P + 2m^2\mathbb P(\Omega) < \infty.
\end{align*}
Thus
\begin{align*}
\operatorname{Var}(X) = \mathbb E[(X-m)^2] = \int_\Omega Y\, d\mathbb P
\end{align*}
is finite and well-defined.
[/step]
[step:Deduce non-negativity from the integral representation]
Since $Y(\omega) = (X(\omega)-m)^2 \geq 0$ for every $\omega \in \Omega$, monotonicity of the [Lebesgue integral](/page/Lebesgue%20Integral) gives
\begin{align*}
\operatorname{Var}(X) = \int_\Omega Y\, d\mathbb P \geq 0.
\end{align*}
[/step]
[step:Characterize the zero variance case by vanishing of the squared deviation]
Assume first that $X=m$ $\mathbb P$-a.s. Then $Y=0$ $\mathbb P$-a.s., and therefore
\begin{align*}
\operatorname{Var}(X) = \int_\Omega Y\, d\mathbb P = 0.
\end{align*}
Conversely, assume that $\operatorname{Var}(X)=0$. For each $k \in \mathbb N$, define the event
\begin{align*}
A_k := \{\omega \in \Omega : Y(\omega) \geq 1/k\}.
\end{align*}
Since $Y$ is measurable, $A_k \in \mathcal F$. Using $Y \geq (1/k)\mathbb 1_{A_k}$ pointwise, monotonicity of the integral gives
\begin{align*}
0 = \int_\Omega Y\, d\mathbb P \geq \int_\Omega \frac{1}{k}\mathbb 1_{A_k}\, d\mathbb P = \frac{1}{k}\mathbb P(A_k).
\end{align*}
Hence $\mathbb P(A_k)=0$ for every $k \in \mathbb N$.
Define the event
\begin{align*}
A := \{\omega \in \Omega : Y(\omega) > 0\}.
\end{align*}
Then
\begin{align*}
A = \bigcup_{k=1}^{\infty} A_k.
\end{align*}
Indeed, if $Y(\omega)>0$, then choosing $k \in \mathbb N$ with $k \geq 1/Y(\omega)$ gives $Y(\omega)\geq 1/k$, so $\omega \in A_k$. [Countable subadditivity](/theorems/1108) gives
\begin{align*}
\mathbb P(A) \leq \sum_{k=1}^{\infty} \mathbb P(A_k) = 0.
\end{align*}
Thus $Y=0$ $\mathbb P$-a.s. Since $Y=(X-m)^2$, this is equivalent to $X=m$ $\mathbb P$-a.s., that is,
\begin{align*}
\mathbb P\left(\{\omega \in \Omega : X(\omega)=\mathbb E[X]\}\right)=1.
\end{align*}
[guided]
We prove both directions of the equality statement.
First suppose that $X=m$ $\mathbb P$-a.s., where
\begin{align*}
m := \mathbb E[X].
\end{align*}
Then the squared deviation
\begin{align*}
Y: (\Omega, \mathcal F) &\to ([0,\infty), \mathcal B([0,\infty))) \\
\omega &\mapsto (X(\omega)-m)^2
\end{align*}
satisfies $Y=0$ $\mathbb P$-a.s. Integrating the zero almost-sure representative gives
\begin{align*}
\operatorname{Var}(X)=\int_\Omega Y\, d\mathbb P=0.
\end{align*}
Now suppose instead that
\begin{align*}
\operatorname{Var}(X)=\int_\Omega Y\, d\mathbb P=0.
\end{align*}
The point is to turn an integral statement into a pointwise almost-sure statement. Because $Y$ is non-negative, any set on which $Y$ is bounded below by a positive number must have probability zero; otherwise the integral would be positive.
For each $k \in \mathbb N$, define
\begin{align*}
A_k := \{\omega \in \Omega : Y(\omega) \geq 1/k\}.
\end{align*}
The measurability of $Y$ implies $A_k \in \mathcal F$. On all of $\Omega$, we have the pointwise inequality
\begin{align*}
Y \geq \frac{1}{k}\mathbb 1_{A_k}.
\end{align*}
Therefore monotonicity of the Lebesgue integral gives
\begin{align*}
0 = \int_\Omega Y\, d\mathbb P \geq \int_\Omega \frac{1}{k}\mathbb 1_{A_k}\, d\mathbb P = \frac{1}{k}\mathbb P(A_k).
\end{align*}
Since $\mathbb P(A_k)\geq 0$, this forces
\begin{align*}
\mathbb P(A_k)=0
\end{align*}
for every $k \in \mathbb N$.
It remains to pass from the sets where $Y$ is at least a fixed positive threshold to the set where $Y$ is merely positive. Define
\begin{align*}
A := \{\omega \in \Omega : Y(\omega)>0\}.
\end{align*}
Then
\begin{align*}
A = \bigcup_{k=1}^{\infty} A_k.
\end{align*}
The inclusion $\bigcup_{k=1}^{\infty} A_k \subset A$ follows because $1/k>0$. Conversely, if $\omega \in A$, then $Y(\omega)>0$, so there exists $k \in \mathbb N$ with $1/k \leq Y(\omega)$; hence $\omega \in A_k$. Therefore the equality of sets holds.
By countable subadditivity,
\begin{align*}
\mathbb P(A) \leq \sum_{k=1}^{\infty} \mathbb P(A_k)=0.
\end{align*}
Thus $\mathbb P(A)=0$, meaning $Y=0$ $\mathbb P$-a.s. Since
\begin{align*}
Y(\omega)=(X(\omega)-m)^2,
\end{align*}
the condition $Y(\omega)=0$ is equivalent to $X(\omega)=m$. Hence
\begin{align*}
\mathbb P\left(\{\omega \in \Omega : X(\omega)=\mathbb E[X]\}\right)=1.
\end{align*}
[/guided]
[/step]