A path-integral approach to the quantization of the electromagnetic field in a linearly amplifying magnetodielectric medium is presented. Two continua of inverted harmonic oscillators are used to describe the polarizability and magnetizability of the amplifying medium. The causal susceptibilities of the amplifying medium, with negative imaginary parts in finite frequency intervals, are identified and their relationships to microscopic coupling functions are determined. By carefully relating the two-point functions of the field theory to the optical Green functions, we calculate the Casimir energy and Casimir forces for a multilayer magnetodielectric medium with both gain and loss. We point out the essential differences with a purely passive layered medium. For a single layer, we find different bounds on the Casimir force for fully amplifying and for lossy media. The force is attractive in both cases, even if the medium exhibits negative refraction. From our Lagrangian we also derive by canonical quantization the postulates of the phenomenological theory of amplifying magnetodielectrics.