We shall generalize this by proving that
Any closed convex subset of $\mathbb R^n$ is a strong deformation retract of $\mathbb R^n$.
Let $C$ be a closed convex subset of $\mathbb R^n$. For each $x \notin C$ we have
$$d(x,C) = \inf\{\lVert x - y \rVert : y \in C \} > 0 ,$$
because otherwise we would find a sequence $(y_n)$ in $C$ such that $y_n \to x$. But then we would have $x \in C$ since $C$ is closed.
Note that the definition of $d(x,C)$ is based on the Euclidean norm. This will be essential for our proof. See the remark below.
There exists $y \in C$ such that $\lVert x - y \rVert = d(x,C)$. In fact, let $y_n \in C$ such that $\lVert x - y_n \rVert < d(x,C) + 1/n$. This sequence is bounded by $\lVert x \rVert + d(x,C) + 1$, thus has a convergent subsequence, so we may assume w.l.o.g. that $(y_n)$ converges to some $y \in \mathbb R^n$. Since $C$ is closed, we have $y \in C$ and $\lVert x - y \rVert = d(x,C)$.
We claim that $y$ is unique because $C$ is convex. So assume that $y' \in C$ is point $y' \ne y$ such that $\lVert x - y \rVert = \lVert x - y' \rVert$. The points $x, y, y'$ span an affine Euclidean plane $E^2 \subset \mathbb R^n$ and form an isosceles triangle. The midpoint $y'' = 1/2 y + 1/2y'$ of the line segment between $y, y'$ is contained in $C$. The points $x,y, y''$ form a right-angled triangle, thus $\lVert x - y \rVert^2 = \lVert x - y'' \rVert^2 + \lVert y - y'' \rVert^2$ which gives $\lVert x - y \rVert > \lVert x - y'' \rVert$, a contradiction.
Remark: As pointed out in a comment by copper.hat, we use a special property of the Euclidean norm $\lVert - \rVert$: It is strictly convex, which means that any closed ball $B$ is a strictly convex set in the sense that every point on the line segment connecting two points $x, y \in B$ other than the endpoints is inside the interior of $B$. I proved a special case of this (for the midpoint of the line segment) using the Pythagorean theorem. Note that other norms may not have this property.
Define
$$r : \mathbb R^n \to C, r(x) = \begin{cases} x & x \in C \\ \text{unique } y \in C \text{ such that } \lVert x - y \rVert = d(x,C) & x \notin C \end{cases}$$
Let us prove that $r$ is continuous (i.e. that $r$ is a retraction).
Continuity is obvious in all interior points of $C$.
Let us now consider a boundary point $\xi$ of $C$. Let $\epsilon > 0$ and $x \in \mathbb R^n$ such that $\lVert x - \xi \rVert < \epsilon/2$. We claim that $\lVert r(x) - r(\xi) \rVert = \lVert r(x) - \xi \rVert < \epsilon$. This is trivial for $x \in C$. For $x \notin C$ we have $\lVert r(x) - \xi \rVert \le \lVert r(x) - x \rVert + \lVert x - \xi \rVert = d(x,C) + \lVert x - \xi \rVert \le 2 \lVert x - \xi \rVert < \epsilon$.
Let us finally consider a point $\xi \notin C$. In the sequel it will be useful to draw pictures to understand geometrically what is going on.
We begin with a preparation. Let $P^{n-1}(x)$ denote the affine hyperplane which contains $r(x)$ and is orthogonal to the line through $x$ and $r(x)$ (i.e. $P^{n-1}(x) = \{r(x) + y : \langle y, x - r(x) \rangle = 0\}$ , where $\langle -, - \rangle$ denotes the standard inner product). This is the tangent hyperplane of the sphere $S^{n-1}(x;d(x,C))$ with center $x$ and radius $d(x,C)$ at the point $r(x)$. $P^{n-1}(x)$ divides $\mathbb R^n$ in two open half-spaces. Let $H^n(x)$ denote the open half-space containing $x$ (i.e. $H^n(x) = \{r(x) + y : \langle y, x - r(x) \rangle > 0\}$). We claim that $H^n(x) \cap C = \emptyset$. Assume there exists $y \in H^n(x) \cap C$. The points $x, r(x), y$ are contained in an affine Euclidean plane $E^2 \subset \mathbb R^n$ (if $y$ lies on the line through $x$ and $r(x)$, then $E^2$ is not unique, but that does not matter). The set $S' = E^2 \cap S^{n-1}(x;d(x,C))$ is a circle in $E^2$, and $L = E^2 \cap P(x)$ is the tangent line to $S'$ at $r(x)$. The circle $S'$ bounds the open disk $D^2(x,d(x,C)) \subset E^2$ with center $x$ and radius $d(x,C)$. Clearly $y \notin D^2(x,d(x,C))$ because otherwise $d(x,C) \le \lVert y - x \rVert < d(x,C)$. The line $L(y)$ through $y$ and $r(x)$ is different from $L$, thus $D^2(x,d(x,C)) \cap L(y)$ is non-empty. Let $y' \in D^2(x,d(x,C)) \cap L(y)$. Since $y \notin D^2(x,d(x,C))$, the point $y'$ lies between $y$ and $r(x)$, thus $y' \in C$ because $C$ is convex. Therefore $d(x,C) \le d(x,y') < d(x,C)$, a contradiction.
Now let $ 0 < \epsilon \le d(x,C)$ and $x \in \mathbb R^n$ such that $\lVert x - \xi \rVert < \epsilon/2$. Note that this assures $x \in H^n(\xi)$. We claim that $\lVert r(x) - r(\xi) \rVert < \epsilon$. Let $\rho(x) \in P^{n-1}(\xi)$ be the unique point such that line $L_x$ through $x$ and $\rho(x)$ is orthogonal to $P^{n-1}(\xi)$. We have $\lVert \rho(x) - r(\xi) \rVert < \epsilon/2$: Note that in the quadrilateral with vertices $\xi, x, r(\xi), \rho(x)$ (which span an affine Euclidean plane $E^2 \subset \mathbb R^n$) the edges $\overline{\xi r(\xi)}$ and $\overline{x \rho(x)}$ are parallel with distance $\lVert \rho(x) - r(\xi) \rVert$, thus $\lVert \rho(x) - r(\xi) \rVert \le$ length of the edge $\overline{x \xi}$ which is $\lVert x - \xi \rVert < \epsilon/2$. We have $d(x,C) \le d(x,r(\xi))$, thus $r(x)$ is contained in the closed ball $\bar D^n(x,d(x,r(\xi))) \subset \mathbb R^n$ with center $x$ and radius $d(x,r(\xi))$. Since $H^n(\xi) \cap C = \emptyset$, we must have $r(x) \in D' = \bar D^n(x,d(x,r(\xi))) \cap G^n(\xi)$, where $G^n(\xi) = \mathbb R^n \setminus H^n(\xi)$ is the closed half-space bounded by $H^{n-1}(\xi)$ and not containing $\xi$. The intersection $D'' = \bar D^n(x,d(x,r(\xi))) \cap P^{n-1}(\xi)$ is a closed ball in $P^{n-1}(\xi)$ with center $\rho(x)$ and radius $R = \lVert \rho(x) - r(\xi) \rVert < \epsilon$. Thus $D'$ is a spherical dome of $\bar D^n(x,d(x,r(\xi)))$ with base $D''$. The diameter of $D'$ equals the diameter of $D''$ which is $2R$. Thus $\lVert r(x) - r(\xi) \rVert \le 2R < \epsilon$.
$r$ is in fact a strong deformation retraction. Look at
$$H: \mathbb R^n \times I \to \mathbb R^n, H(x,t) = (1-t)x + tr(x) .$$