From Leo Babauta's Zen Habits:
Recently I’ve had another slight bout of insomnia, and so I rediscovered a trick I learned several years ago. It’s so simple it seems like it can’t possibly work, but it unfailingly does.
The simplest cure for insomnia: get comfortable and close your eyes, and then replay your day in your head, in every detail possible, from the moment you woke up. Start from the moment your eyes opened, and replay every movement -- getting out of bed, starting the coffeemaker, going to the bathroom, washing your hands, or whatever. Don’t summarize -- leave nothing out.
It works. I’ve never made it to mid-morning in my mind movies. I inevitably fall asleep. It’s much better than counting sheep (I’ve tried) and even better than meditation (I’ve done that too). Try it, and when it works, praise me in your dreams.[Updated 4.13.11: I tried this last night, and it worked like a charm...]
[Source]