Cavity-mediated light-matter coupling can dramatically alter opto-electronic and physico-chemical properties of a molecule. Ab initio theoretical predictions of these systems need to combine non-perturbative, many-body electronic structure theory-based methods with cavity quantum electrodynamics and theories of open quantum systems. Here we generalize quantum-electrodynamical density functional theory to account for dissipative dynamics and describe coupled cavity-molecule interactions in the weak-to-strong-coupling regimes. Specifically, to establish this generalized technique, we study excited-state dynamics and spectral responses of benzene and toluene under weak-to-strong light-matter coupling. By tuning the coupling we achieve cavity-mediated energy transfer between electronic excited states. This generalized ab initio quantum-electrodynamical density functional theory treatment can be naturally extended to describe cavity-mediated interactions in arbitrary electromagnetic environments, accessing correlated light-matter observables and thereby closing the gap between electronic structure theory and quantum optics.