It may be a bit surprising, but charges simply are not conserved in such a theory. A heuristic handwaving way of explaining this is to suppose there is a Dirac sea of fermions and a large (and therefore adiabatic) instanton suddenly appears, and suddenly, the energy levels gradually shift upwards or downwards. This means particles which once belonged to the Dirac sea suddenly become conspicious particles and what looks like a particle creation happens. This isn't a very satisfactory explanation, however.
Wess and Zumino developed a set of conditions on how the partition function ought to behave under gauge transformations called the Wess-Zumino consistency conditions.
Fujikawa derived this anomaly using the correspondence between functional determinants and the partition function using the Atiyah-Singer index theorem.
See also Global anomaly, Gravitational anomaly