Under the stated gauge transformation, the charged-particle electromagnetic Lagrangian becomes
Thus
The action changes only by , whose variation vanishes for fixed endpoints. By total-time-derivative invariance of a Lagrangian, the Euler-Lagrange equation is unchanged.