The paper approaches in an elaborate manner the $n$-body problem from celestial mechanics with the tools of the mathematical theory of optimal processes, namely the Pontryagin maximum principle. The setup of the problem is given by the equations $dr_j/dt=V_j$, $dA/dt=\{\sum_{j=1}^nm_jV_j^2/2\}+G\sum_{1\leq j<k\leq n}m_jm_k/r_{jk}$; here, $G$ is the constant of the law of universal attraction, $r_{jk}$ is the distance between two point masses $m_j$, $m_k$, and $A$ is the action to be minimized (between the initial and final positions of the $n$ point masses at given initial and final times). The positions of the point masses and the action are state parameters while velocities are control parameters. Section 2 contains a detailed presentation of the theory of optimization of deterministic dynamical systems (including relevant references). Following the author’s terminology, for a (natural) negative Pontryagin coefficient, the optimal Hamiltonian (the maximum of the Hamiltonian in the control domain) reads as $H^{*}=\{-\sum_{j=1}^np_j^2/2p_Am_j\}+Gp_A$ $\sum_{1\leq j<k\leq n}m_jm_k/r_{jk}$ (the sign $-$ should be added to the original formulation, in my opinion) and is obtained for $V_j=-p_j/p_Am_j$, where $p_j$ (the Pontryagin vector) is the momentum of the point mass $m_j$. The Pontryagin maximum principle shows that, if the singularities and especially collisions are avoided, the Pontryagin solutions are also solutions of the $n$-body problem. The paper further analyzes the singularities: by showing that the minimum of the action is bounded (Subsection 4.1), $0<A_f\leq K<+\infty $, and using the formula $\left\vert r_{j_2}-r_{j_1}\right\vert \leq [2K(t_2-t_1)/m_j]^{1/2}$, where $t_i$, $r_{j_i}$ are arbitrary succesive instants, respectively positions, it is inferred that the eventual singularities (at intermediate times) are necessarily collisions; using a “reductio ad absurdum” method, a thorough analysis of binary/multiple collisions is performed (this is the core of the paper, Subsection 4.3): it can be concluded that the minimizing solutions are pure $n$-body motions with no intermediate collisions even if one or several collisions are imposed at initial and/or final times. As a by-product, in the case of eventual binary collisions, a Lambert-type theorem is derived: there are five relations between the parameters $T$ (the time necessary to go from the initial position $r_{+}$ to the final position $r_{-}$: $T=t_{+}-t_{-}$), $\Sigma $ (the quantity $\left\vert r_{+}+r_{-}\right\vert $), $a$ (the semimajor axis of the relative two-body orbit), $M$ (the quantity $\left\vert r_{+}-r_{-}\right\vert $), $A_{in}$ (the inner action: $[m_jm_k/(m_j+m_k)]\int_{t_{-}}^{t_{+}}[(V^2/2)+(\mu /r)]dt$, where $V=\left\vert (d/dt)(r_k-r_j)\right\vert $, $\mu =G(m_j+m_k)$ and $r=\left\vert r_k-r_j\right\vert $), $\Delta $ (the difference between initial eccentric anomalies: $E_{+}-E_{-}$; $F_{+}-F_{-}$ in the hyperbolic case), $S$ (the quantity $e($sin$E_{+}-$sin$E_{-})$; in the hyperbolic case: $e($sinh$F_{+}-$sinh$F_{-})$, where $e$ is the eccentricity of the two-body orbit) and $C$ (the quantity $e($cos$E_{+}+$cos$E_{-})$; in the hyperbolic case: $e($cosh$F_{+}+$cosh$F_{-})$). The case of infinitesimal masses is discussed in Appendix 4, and an application to periodic solutions is given in Appendix 5.