[proofplan]
We argue by contraposition. Suppose $f$ factors nontrivially over $\mathbb{Q}$. By [Gauss's Lemma](/theorems/???), primitivity of $f$ allows us to lift this to a nontrivial factorisation over $\mathbb{Z}$. Reducing that factorisation modulo $p$ and using the hypothesis $\deg \bar{f} = n$ produces a nontrivial factorisation of $\bar{f}$ in $\mathbb{F}_p[x]$, contradicting the assumed irreducibility of $\bar{f}$.
[/proofplan]
[step:Assume $f$ factors nontrivially over $\mathbb{Q}$ and lift to a factorisation over $\mathbb{Z}$]
Suppose for contradiction that $f$ is reducible over $\mathbb{Q}$. Then there exist polynomials $g, h \in \mathbb{Q}[x]$ with $1 \le \deg g < n$ and $1 \le \deg h < n$ such that $f = gh$.
Since $f \in \mathbb{Z}[x]$ is primitive, [Gauss's Lemma](/theorems/???) applies: if a primitive polynomial in $\mathbb{Z}[x]$ factors over $\mathbb{Q}$, then it factors over $\mathbb{Z}$. Concretely, Gauss's Lemma guarantees the existence of polynomials $g_0, h_0 \in \mathbb{Z}[x]$ with
\begin{align*}
f = g_0 h_0, \quad \deg g_0 = \deg g \ge 1, \quad \deg h_0 = \deg h \ge 1.
\end{align*}
In particular, $\deg g_0 + \deg h_0 = \deg f = n$, and both $\deg g_0 < n$ and $\deg h_0 < n$.
[guided]
We proceed by contradiction: assume $f$ is reducible over $\mathbb{Q}$. This means there exist $g, h \in \mathbb{Q}[x]$ with $\deg g \ge 1$ and $\deg h \ge 1$ such that $f = gh$. Since $\deg f = n$, we have $\deg g + \deg h = n$, so both degrees are strictly less than $n$.
The factorisation $f = gh$ is a priori over $\mathbb{Q}$, not over $\mathbb{Z}$. The factors $g$ and $h$ may have rational (non-integer) coefficients. Why can we move to integer coefficients? The key obstacle is that $\mathbb{Q}[x]$ contains polynomials with fractional coefficients such as $\tfrac{1}{2}x + \tfrac{3}{4}$, and we need factors in $\mathbb{Z}[x]$.
This is exactly the content of [Gauss's Lemma](/theorems/???). The version we need states: if $f \in \mathbb{Z}[x]$ is primitive and $f = gh$ with $g, h \in \mathbb{Q}[x]$, then there exist $g_0, h_0 \in \mathbb{Z}[x]$ with $f = g_0 h_0$ and $\deg g_0 = \deg g$, $\deg h_0 = \deg h$. The mechanism is to clear denominators from $g$ and $h$ and then redistribute any integer content: write $g = \tfrac{a}{b} g_0'$ and $h = \tfrac{c}{d} h_0'$ with $g_0', h_0' \in \mathbb{Z}[x]$ primitive, so $f = \tfrac{ac}{bd} g_0' h_0'$. Since $f$ is primitive, Gauss's Lemma (the product of primitive polynomials is primitive) forces $\tfrac{ac}{bd} = \pm 1$, giving $f = \pm g_0' h_0'$ as a factorisation in $\mathbb{Z}[x]$.
The hypothesis that $f$ is primitive is essential here. If $f$ had a non-trivial content $c(f) > 1$, the argument above would only yield $\tfrac{ac}{bd} = \pm c(f)$, and we could not conclude that the factors lie in $\mathbb{Z}[x]$ with the same degrees. Primitivity ensures that any rational content arising from clearing denominators can be absorbed without introducing a non-unit constant factor.
Applying Gauss's Lemma, we obtain $g_0, h_0 \in \mathbb{Z}[x]$ with
\begin{align*}
f = g_0 h_0, \quad \deg g_0 = \deg g \ge 1, \quad \deg h_0 = \deg h \ge 1.
\end{align*}
In particular, $\deg g_0 + \deg h_0 = n$ and both $\deg g_0 < n$ and $\deg h_0 < n$. This is a nontrivial factorisation of $f$ over $\mathbb{Z}$.
[/guided]
[/step]
[step:Reduce the factorisation modulo $p$ and derive a contradiction]
Let $\pi: \mathbb{Z}[x] \to \mathbb{F}_p[x]$ denote the canonical ring homomorphism that sends each coefficient $a_k$ to its residue class $\bar{a}_k \in \mathbb{F}_p$. Since $\pi$ is a ring homomorphism, it preserves products:
\begin{align*}
\bar{f} = \pi(f) = \pi(g_0 h_0) = \pi(g_0)\, \pi(h_0) = \bar{g}_0\, \bar{h}_0.
\end{align*}
We now verify the degrees. Since $\deg g_0 \ge 1$, let $a$ denote the leading coefficient of $g_0$ and $b$ the leading coefficient of $h_0$. The leading coefficient of $f = g_0 h_0$ is $ab$. By the hypothesis $\deg \bar{f} = n = \deg f$, the leading coefficient of $f$ does not vanish modulo $p$, i.e., $p \nmid ab$. Since $p$ is prime, $p \nmid ab$ implies $p \nmid a$ and $p \nmid b$. Therefore $\bar{a} \neq 0$ and $\bar{b} \neq 0$ in $\mathbb{F}_p$, which gives
\begin{align*}
\deg \bar{g}_0 = \deg g_0 \ge 1, \quad \deg \bar{h}_0 = \deg h_0 \ge 1.
\end{align*}
The factorisation $\bar{f} = \bar{g}_0\, \bar{h}_0$ is therefore nontrivial in $\mathbb{F}_p[x]$, since both factors have degree at least $1$ and strictly less than $n = \deg \bar{f}$. This contradicts the hypothesis that $\bar{f}$ is irreducible in $\mathbb{F}_p[x]$.
[guided]
We now reduce the integer factorisation modulo $p$ and show it yields a nontrivial factorisation of $\bar{f}$, contradicting irreducibility.
Define the reduction map $\pi: \mathbb{Z}[x] \to \mathbb{F}_p[x]$ by applying the canonical surjection $\mathbb{Z} \to \mathbb{Z}/p\mathbb{Z} = \mathbb{F}_p$ to each coefficient. This map $\pi$ is a ring homomorphism because the coefficient-wise operations in $\mathbb{Z}[x]$ (addition and the Cauchy product for multiplication) descend to the corresponding operations in $\mathbb{F}_p[x]$ under the ring homomorphism $\mathbb{Z} \to \mathbb{F}_p$. In particular, $\pi$ preserves products: $\pi(g_0 h_0) = \pi(g_0)\, \pi(h_0)$.
Applying $\pi$ to the factorisation $f = g_0 h_0$ gives
\begin{align*}
\bar{f} = \bar{g}_0\, \bar{h}_0 \quad \text{in } \mathbb{F}_p[x].
\end{align*}
The critical question is: does reduction modulo $p$ preserve the degrees of $g_0$ and $h_0$? Reduction can only lower the degree of a polynomial (if the leading coefficient vanishes modulo $p$), so in general $\deg \bar{g}_0 \le \deg g_0$ and $\deg \bar{h}_0 \le \deg h_0$. We need to rule out degree drops.
Let $a$ be the leading coefficient of $g_0$ and $b$ the leading coefficient of $h_0$. Since $\mathbb{Z}$ is an integral domain and $\deg g_0 + \deg h_0 = n$, the leading coefficient of $f = g_0 h_0$ is $ab$ (the product of the leading coefficients is the leading coefficient of the product in an integral domain). The hypothesis $\deg \bar{f} = n$ means that $p$ does not divide the leading coefficient of $f$, i.e., $p \nmid ab$.
Now we use that $p$ is prime: $p \nmid ab$ implies $p \nmid a$ and $p \nmid b$ (this is the defining property of a prime element in $\mathbb{Z}$, or equivalently the fact that $\mathbb{F}_p$ is an integral domain). Therefore $\bar{a} \neq 0$ in $\mathbb{F}_p$ and $\bar{b} \neq 0$ in $\mathbb{F}_p$, so
\begin{align*}
\deg \bar{g}_0 = \deg g_0 \ge 1, \quad \deg \bar{h}_0 = \deg h_0 \ge 1.
\end{align*}
Moreover, $\deg \bar{g}_0 + \deg \bar{h}_0 = \deg g_0 + \deg h_0 = n = \deg \bar{f}$, and both $\deg \bar{g}_0 < n$ and $\deg \bar{h}_0 < n$.
Therefore $\bar{f} = \bar{g}_0\, \bar{h}_0$ is a nontrivial factorisation of $\bar{f}$ in $\mathbb{F}_p[x]$: both factors have positive degree strictly less than $\deg \bar{f}$. This contradicts the hypothesis that $\bar{f}$ is irreducible in $\mathbb{F}_p[x]$.
[/guided]
[/step]
[step:Conclude that $f$ is irreducible over $\mathbb{Q}$]
The assumption that $f$ is reducible over $\mathbb{Q}$ has led to a contradiction with the irreducibility of $\bar{f}$ in $\mathbb{F}_p[x]$. Therefore $f$ is irreducible over $\mathbb{Q}$.
[/step]