Let $g$ be your spacetime metric. We can define the energy functional
$$E(\gamma) = \frac12\int_0^1g(\dot\gamma(t),\dot\gamma(t))dt$$
on curves $\gamma$ in your space. The Euler-Lagrange equations for this functional is the geodesic equation. Likewise we can define the length functional
$$\ell(\gamma) = \int_0^1\sqrt{g(\dot\gamma(t),\dot\gamma(t))}dt,$$
which maps a curve to its length. It is not hard to see that curves that extremize the former automatically extremize the latter, for details, see wikipedia. In particular, a geodesic always extremizes the path length.
Depending on the topology of spacetime, it does not have to be a global extremal though. For example, on a cylinder $\mathbb R\times S^1$ with the Minkowski metric, consider the points $(0,P)$ and $(1,P)$ where $P$ is any point on the circle $S^1$. Then the curve $\gamma(t) = (t,P)$ gives a geodesic, but you get another one wrapping around the circle $n$ times for every $n$. To find these, just unroll the cylinder into $\mathbb R\times \mathbb R$ and draw straight lines, which we already know are geodesics in Minkowski space.