Patients with chronic pain often suffer from sleep disturbances, specifically decreased deep sleep, and thus may get into a vicious circle which maintains their pain condition. Utilizing polysomnography and psychometry, objective and subjective sleep and awakening quality was investigated in 11 patients with nonorganic insomnia (F51.0) related to somatoform pain disorder (SPD; F45.4) as compared with age- and sex-matched healthy controls of the Siesta normative database. Patients demonstrated a markedly deteriorated Pittsburgh Sleep Quality Index, a decreased Quality of Life Index, slightly increased self-reported anxiety (Zung SAS) and depression scores (Zung SDS), as well as an increased Epworth Sleepiness Scale and International Restless Legs Syndrome Scale score. Subjective sleep and awakening quality was markedly reduced, while somatic complaints were increased. Polysomnographic evaluation by a recently developed automatic sleep classifier (Somnolyzer 24 × 7) based on the rules of Rechtschaffen and Kales demonstrated reduced slow-wave sleep (SWS), the target variable in the present study, a decreased stage shift index, increased SWS latency and stage 4 sleep (S4) latency and an increased frequency of shifts from S2 to wakefulness (W) in patients as compared with controls. Minimal oxygen saturation was found decreased, periodic leg movements (PLMs) were increased. In the morning, patients showed deteriorated well-being, drive, mood and wakefulness. There were no significant noopsychic or psychophysiological differences between patients and controls (except for a reduced numerical memory and a slightly increased morning diastolic blood pressure in patients). Subsequent evaluation of the acute effects of 100 mg of a controlled-release formulation of trazodone (Trittico® retard) in the patients demonstrated an increase in the target variable SWS, accompanied by a reduction in the number of awakenings and stage shifts. It normalized the frequency of shifts from S2 to W and reduced the frequency of shifts from W to S1, from S1 to S2, as well as from any stage to S1 and S2. Trazodone, however, also significantly reduced the total sleep period and S2 and increased the latency to S1. Moreover, the drug increased the reduced minimal O2 saturation, reduced the arousal index and the PLMs-in-wake index and normalized the increased morning diastolic blood pressure. In conclusion, our study demonstrated that SPD induced significant changes in subjective and objective sleep and awakening quality, which were partially mitigated by trazodone therapy. The data on the target variable SWS support our hypothesis of a key-lock principle in the diagnosis and drug treatment of sleep disorders. Our study provided the first evidence on the usefulness of the Somnolyzer 24 × 7 and the Siesta database in clinical practice.