5. Find all integer pairs $(a, b)$, where $a \geqslant 1, b \geqslant 1$, and satisfy the equation $a^{b^{2}}=b^{a}$.
$$
b=3, a=b^{k}=3^{3}=27 \text {. }
$$

In summary, all positive integer pairs that satisfy the equation are
$$
(a, b)=(1,1),(16,2),(27,3) .
$$
Obviously, when $a, b$ have one equal to 1, $(a, b)=(1, 1)$. Now assume $a, b \geqslant 2$.

Let $t=\frac{b^{2}}{a}$, then from the equation in the problem we get $b=a^{t}, a t=a^{2 t}$, thus $t=a^{2 t-1}$. Therefore, $t>0$. If $2 t-1 \geqslant 1$, then $t=a^{2 t-1} \geqslant(1+1)^{2 t-1} \geqslant 1+(2 t-1)=2 t>t$, which is a contradiction. So $2 t-1<1$ and $t$ is a rational number. From $a=b^{k}$ we have
$$
k=b^{k-2} \text{.}
$$

If $k \leqslant 2$, then $k=b^{k-2} \leqslant 1$, which contradicts the previously proven $k>1$, so $k>2$. Let $k=\frac{p}{q}, p, q \in \mathbb{N}, (p, q)=1$, then $p>2q$. Thus, from (1) we get
$$
\left(\frac{p}{q}\right)^{q}=k^{q}=b^{p-2q} \in \mathbb{Z}.
$$

This implies $q^{q} \mid p^{q}$. But $p, q$ are coprime, so $q=1$, meaning $k$ is a natural number greater than 2.
When $b=2$, from (1) we get $k=2^{k-2}$, so $k \geqslant 4$. Also,
$$
\begin{array}{l}
k=2^{k-2} \geqslant C_{k-2}^{0}+C_{k-2}^{1}+C_{k-2}^{2} \\
=1+(k-2)+\frac{(k-2)(k-3)}{2} \\
=1+\frac{(k-1)(k-2)}{2} \geqslant 1+(k-1)=k,
\end{array}
$$

equality holds if and only if $k=4$, so,
$$
\begin{array}{l}
a=b^{k}=2^{4}=16. \\
\text{When } b \geqslant 3, \\
k=b^{k-2} \geqslant(1+2)^{k-2} \geqslant 1+2(k-2) \\
\quad=2 k-3.
\end{array}
$$

Thus, $k \leqslant 3$. This implies $k=3$. Therefore,