The Hamiltonian function (H), if it exists, provides a powerful platform for studying the dynamics of constrained many-particle systems. For systems under holonomic constraints, H can be derived from the principle of least action (PLA) formulated in terms of a suitable set of generalized coordinates. In molecular dynamics (MD) simulations, where the system temperature often prescribes a non-holonomic constraint, the challenge is to find the system’s Hamiltonian. The Gaussian Isokinetic (GIK) thermostat, the first deterministic physics-preserving thermostat in MD, was derived from the principle of least constraint (PLC) in the early 1980s: its H, interestingly, was discovered almost 15 years later. A mathematically rigorous connection of the GIK Hamiltonian with PLA, however, has been missing until now. In this article, we adopt a variational approach to establish the equivalence of PLC with PLA for a class of non-holonomically constrained many-particle systems, and present the general formulation of the Euler–Lagrange equations of motion through time rescaling. Making use of the particular forms of the Lagrange multiplier obtained from the principle of least constraint, we derive H for the GIK and the Gaussian Isoenergetic thermostats.