5. In rectangle $A B C D$, $A B=1, B C=2$, point $E$ is on side $B C$, and point $F$ is on side $C D$. If $|\overrightarrow{E F}|=1$, then the minimum value of $\overrightarrow{A E} \cdot \overrightarrow{A F}$ is
5. $5-\sqrt{5}$.

As shown in Figure 6, with $A$ as the origin, the rays $A B$ and $A D$ are the positive directions of the $x$-axis and $y$-axis, respectively, to establish a Cartesian coordinate system. By the problem, we can set point $E(1, y), F(x, 2)$, then $\overrightarrow{A E} \cdot \overrightarrow{A F}=2 y+x$. From $|\overrightarrow{E F}|=1$, we get
$$
(x-1)^{2}+(y-2)^{2}=1,
$$

and $0 \leqslant x \leqslant 1,1 \leqslant y \leqslant 2$.
Thus, the problem is converted to: the moving point $W$ is on the quarter unit circle $(x-1)^{2}+(y-2)^{2}=1(0 \leqslant x \leqslant 1$, $1 \leqslant y \leqslant 2)$, find the minimum value of $t=2 y+x$.

As shown in Figure 7, when the line with a slope of $-\frac{1}{2}$ is tangent to the above quarter unit circle at point $\left(1-\frac{\sqrt{5}}{5}, 2-\frac{2 \sqrt{5}}{5}\right)$, $t=2 y+x$ achieves its minimum value $5-\sqrt{5}$.