A gauge-invariant formulation of constrained variational calculus, based on the introduction of the bundle of affine scalars over the configuration manifold, is presented. In the resulting setup, the "Lagrangian" ℒ is replaced by a section of a suitable principal fiber bundle over the velocity space. A geometric rephrasement of Pontryagin's maximum principle, showing the equivalence between a constrained variational problem in the state space and a canonically associated free one in a higher affine bundle, is proved.