NREM sleep is characterized by two hallmarks, namely K-complexes (KCs) during sleep stage N2 and cortical slow oscillations (SOs) during sleep stage N3. While the underlying dynamics on the neuronal level is well known and can be easily measured, the resulting behavior on the macroscopic population level remains unclear. On the basis of an extended neural mass model of the cortex, we suggest a new interpretation of the mechanisms responsible for the generation of KCs and SOs. As the cortex transitions from wake to deep sleep, in our model it approaches an oscillatory regime via a Hopf bifurcation. Importantly, there is a canard phenomenon arising from a homoclinic bifurcation, whose orbit determines the shape of large amplitude SOs. A KC corresponds to a single excursion along the homoclinic orbit, while SOs are noise-driven oscillations around a stable focus. The model generates both time series and spectra that strikingly resemble real electroencephalogram data and points out possible differences between the different stages of natural sleep. 