Solving the challenging problem of the amplification and generation of an electromagnetic field in nanostructures enables to implement many properties of the electromagnetic field at the nanoscale in novel practical applications. A first-principles quantum mechanical consideration of such a problem is sufficiently restricted by the exponentially large number of degrees of freedom, and does not allow the electromagnetic field dynamics to be described if it involves a high number of interacting atoms and modes of the electromagnetic field. Conversely, the classical description of electromagnetic fields is incorrect at the nanoscale due to the high level of quantum fluctuations connected to high dissipation and noise levels. In this paper, we develop the framework with a significantly reduced number of degrees of freedom, which describes the quantum spatial dynamics of electromagnetic fields interacting with atoms. As an example, we consider the interaction between atoms placed in a metallic subwavelength groove, and demonstrate that a spontaneously excited electromagnetic pulse propagates with the group velocity. The developed approach may be exploited to describe non-uniform amplification and propagation of electromagnetic fields in arbitrary dispersive dissipative systems.