Then, I found a page that said to change power cords. Appearantly the power supply in them is very sensitive, and if the cord isn't pushed in 100%, or if there are problems with the cord, the machine can randomly shut off. I dragged an ugly (but heavy-duty) black cord out of the desk, and switched it after the last power-off. No more problems.
Apple's stock cord is sitting in my trash can, cut in three pieces, (NEVER leave a bad cord intact; someone will want to use it again.) and my iMac is happy. Hopefully, that's the only problem and my iMac can keep humming along happily.
Upda te: It wasn't the power cord. The power supply is dying. Fortunately, my employer bought AppleCare, so the repairman will be there in a day or two.