[guided]We now prove uniqueness. Suppose $a$ has two factorizations $a = p_1 \cdots p_m = q_1 \cdots q_n$ into irreducibles. The argument proceeds by strong induction on $m$, the number of irreducible factors on the left side.
**Base case ($m = 1$).** We have $p_1 = q_1 \cdots q_n$ with $p_1$ irreducible. If $n \ge 2$, then $p_1$ is a product of two or more non-units, contradicting irreducibility. So $n = 1$ and $p_1 = q_1$.
**Inductive step ($m \ge 2$).** Every irreducible in a PID is prime. To see why: if $p$ is irreducible and $p \mid ab$, write $(p, a) = (d)$ since $R$ is a PID. Then $d \mid p$, and irreducibility of $p$ forces either $d \in R^\times$ — giving $(p, a) = R$, so $1_R = rp + sa$ for some $r, s$, and multiplying by $b$ yields $b = rpb + sab$, whence $p \mid b$ — or $d$ and $p$ are associates, giving $p \mid a$. Applying this to $p_1$: since $p_1$ is prime and $p_1 \mid q_1 q_2 \cdots q_n$, the definition of primality gives $p_1 \mid q_j$ for some $j$. (Concretely, apply the definition inductively: $p_1 \mid q_1(q_2 \cdots q_n)$ implies $p_1 \mid q_1$ or $p_1 \mid q_2 \cdots q_n$; if the latter, repeat.) Relabel so that $j = 1$.
Since $p_1 \mid q_1$, write $q_1 = p_1 v$. Now $q_1$ is irreducible and $p_1$ is not a unit (irreducibles are by definition non-units). Since $q_1 = p_1 v$ and $q_1$ is irreducible, one of $p_1, v$ must be a unit. Since $p_1$ is not a unit, $v$ must be a unit. So $q_1$ and $p_1$ are associates.
Cancel $p_1$ from both sides. Since $R$ is an integral domain and $p_1 \neq 0$:
\begin{align*}
p_1 p_2 \cdots p_m &= p_1 v \cdot q_2 \cdots q_n \\
\implies p_2 \cdots p_m &= (v q_2) \cdot q_3 \cdots q_n.
\end{align*}
The element $vq_2$ is irreducible: if $vq_2 = xy$ with $x, y$ non-units, then $q_2 = (v^{-1}x)y$, and since $v$ is a unit, $v^{-1}x$ is a non-unit iff $x$ is a non-unit, contradicting irreducibility of $q_2$. So the right side is a product of $n - 1$ irreducibles. The left side is a product of $m - 1$ irreducibles. By the induction hypothesis (applied to $m - 1 < m$), we get $m - 1 = n - 1$ and the factors match up to reordering and associates.
This is where the proof would fail without the "irreducible implies prime" step. In $\mathbb{Z}[\sqrt{-5}]$, the element $6$ has two essentially different factorizations: $6 = 2 \cdot 3 = (1 + \sqrt{-5})(1 - \sqrt{-5})$. All four factors are irreducible, but $2$ is not prime ($2 \mid (1 + \sqrt{-5})(1 - \sqrt{-5})$ yet $2 \nmid 1 + \sqrt{-5}$ and $2 \nmid 1 - \sqrt{-5}$), so the cancellation argument breaks down.[/guided]