Unfortunately, those systems are known for having capacitor issues, and that's the first thing you want to check.

You need to crack open the case on your system. If you've never done this, it's pretty simple. Turn it off, unplug everything, and lay it flat with the screen down. On the underside of the system (when it's standing up) there are three captive screws you need to loosen. Once you do that, grab hold of the stand, and pull up in a good tug. The whole back panel should pop off. Now you want to look at the internals of the system and you should see clusters of round cylinder things. If any of these seem to be bulging or leaking something that looks like battery acid, then your system is pretty much done for. Repairing this will likely cost more than the system is worth at around $400-$500 and up. You can find repair kits on ebay, but unless you're pretty good with a soldering iron, they're not going to do you any good.

And the bad news for you, is that this is the most likely cause for your problem, and even better, is that it will only get worse with time.

If by some stroke of luck your system is still under warranty, don't walk, RUN to the phone and call this in. Or get it to the local Apple Store ASAP. It seems highly unlikely it would still be under warranty, but by all means check the serial number on Apple's support site.

And if you don't see any issues with the capcitors, the issue is still likely with your logic board, which is just not going to be economical to fix when it will likely be about 60% of a brand new iMac with better specs all around.