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 fibre bundle over the velocity space. A geometric rephrasement of Pontryagins 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.