Let $M\subset \mathbb{R}^n$ be a connected component of an algebraic set $\varphi^{-1}(0)$, where $\varphi$ is a polynomial of degree $d$. Assume that $M$ is contained in a ball of radius $r$. We prove that the geodesic diameter of $M$ is bounded by $2r\nu(n)d(4d-5)^{n-2}$, where $\nu(n)=2{\Gamma({1}/{2})\Gamma(({n+1})/{2})}{\Gamma({n}/{2})}^{-1}$. This estimate is based on the bound $r\nu(n)d(4d-5)^{n-2}$ for the length of the gradient trajectories of a linear projection restricted to $M$.