I would assume a bad connection to power. Check your cord to see if it appears to be loose. If it's not, it's probably something internal and you'll need to take it in to Apple to be repaired.
As the first respondent recommended if you see no obvious problems with the power cord connection its time to assume something is internally wrong and you might need to think about sending it in to Apple for service.
What iMac is it exactly and is it under Applecare coverage?