If you mean the flat panel, flexible neck iMac, then I had a very similar problem a couple of years ago. If I so much as even faintly jogged the table the computer was on, it would instantly disconnect and power off.
I seem to remember that the power cable was not fully inserted at the back of the computer - it looked and felt like it was, but with a good hard push it fully clicked into place and the problem went away.
If this does not sort it out, then it sounds like a loose connection somewhere - possibly in the cable itself and hopefully not in the computer. Possibly you could try and get your hands on another cable and try this out.