iMac keeps restarting without booting up
My iMac suddenly shut down (had a flicker of a blue screen right before) and restarted, but did not get all the way booted up, and then restarted again. It keeps doing that until I manually shut it off. Checked the power supply and did the whole "wait for 30 seconds and then start again" routine multiple times. But its the same behavior. Tried pressing Shift-S and then Apple+S to start in safe mode - did not work. Neither did Shift-R or Apple-R for recovery mode. The device is about 8-9 years old.
iMac Line (2012 and Later)