The conventional perturbation theory in quantum mechanics for the interaction of electromagnetic radiation with matter, which is based on the time-dependent vector and scalar potentials, is shown to be dependent on the gauge. The problem is reformulated, using the approach of Yang, in a gauge-invariant way, in which the transitions between states are induced by the quantum-mechanical power operator. In order to use an unperturbed Hamiltonian which does not involve the electromagnetic field, the gauge is chosen to give the electric dipole interaction. This choice can be made if the magnetic field is negligible and the electric field is slowly varying over atomic dimensions. For a comparison of the gauge-invariant and conventional formulation, a two-level atom in a radiation field is considered. For the probability that an atom originally in the lower state will make a transition to the upper state when the field is not in resonance, the gauge-invariant formulation gives the correct result, whereas the gauge-dependent formulation gives an incorrect result.