The dynamic structure factor is a central quantity describing the physics of quantum many-body systems, capturing structure and collective excitations of a material. In condensed matter, it can be measured via inelastic neutron scattering, which is an energy-resolving probe for the density fluctuations. In ultracold atoms, a similar approach could so far not be applied due to the diluteness of the system. Here, we report on a direct, real-time and non-destructive measurement of the dynamic structure factor of a quantum gas exhibiting cavity-mediated long-range interactions. The technique relies on inelastic scattering of photons, stimulated by the enhanced vacuum field inside a high finesse optical cavity. We extract the density fluctuations, their energy and lifetime while the system undergoes a structural phase transition. We observe an occupation of the relevant quasi-particle mode on the level of a few excitations, and provide a theoretical description of this dissipative quantum many-body system.