I've had my iMac 20 inch for over 6 years and it was starting to die the slow death of frequent shut downs for no reason. My sleuthing proved right - it was a common problem. The power supply needed replacing and Apple was all hands-off, too old of a machine to even have the parts!
The simple sounding repair was more difficult than I'd anticipated. Though the ifixit "How to" video and Apple guide shows how to detach the cable for the power supply it doesn't show how to detach the ambient light sensor connection and I pretty much destroyed that (which isn't a big deal in the use of the mac). Also, removing the actual power drive was much harder - it just wouldn't come out and my finger got sliced, but now I can boast that my blood is inside my mac! Once I finally got the old power supply out - putting in the new one was easy and all so far is working fine (minus the ambient light sensor).
Maybe add a little detail on the ambient light sensor and any advice to help loosen the old power supply which seemed really wedged in tight. Careful with those edges - unless you like to see your blood!