We study discretizations of the Maxwell-Klein-Gordon equation as an example of a constrained geometric non-linear evolution partial differential equation. For the temporal gauge we propose a fully discrete scheme which preserves the non-linear constraint (electric charge) thanks to a special application of Lagrange multipliers. We show that the method generalizes to Hamiltonian wave equations whose kinetic and potential energy are invariant under a group of transformations, even though the Galerkin spaces are not invariant. We then extend the method to the Lorenz gauge. Numerical results illustrate the discussion.