We use large-eddy simulations (LES) to investigate the impact of stable stratification on gravity-wave excitation and energy extraction in a large wind farm. To this end, the development of an equilibrium conventionally neutral boundary layer into a stable boundary layer over a period of 8 h is considered, using two different cooling rates. We find that turbulence decay has considerable influence on the energy extraction at the beginning of the boundary-layer transition, but afterwards, energy extraction is dominated by geometrical and jet effects induced by an inertial oscillation. It is further shown that the inertial oscillation enhances gravity-wave excitation. By comparing LES results with a simple one-dimensional model, we show that this is related to an interplay between wind-farm drag, variations in the Froude number and the dispersive effects of vertically-propagating gravity waves. We further find that the pressure gradients induced by gravity waves lead to significant upstream flow deceleration, reducing the average turbine output compared to a turbine in isolated operation. This leads us to the definition of a non-local wind-farm efficiency, next to a more standard wind-farm wake efficiency, and we show that both can be of the same order of magnitude. Finally, an energy flux analysis is performed to further elucidate the effect of gravity waves on the flow in the wind farm.