That's a kernel panic. Read these websites:
Also, next time you start your Mac after seeing that, you will see a window telling you that a problem has occurred. On that window, select the option to show details and copy the log here, so we can know what's causing your computer to show the kernel panic during shut down
I am probably no able to tell you the cause why your iMac is having a failure. However the autorestart can be because the autorestart function is activated in the following menu:
Go into Systeme Preferences>Energy Saver (Hardware section).
See if the Start up automatically after a power failure is selected.
I will check to see if other options could allow such action as auto restart of your iMac.
I have to admit that the thread from Mende1 is very good and complete.
If you go through the reading from the following link, you should find the answer to your problem.
Try also to see if you have done any hardware changes such as addind a extern drive or add any non Apple App which are non Apple developpers approved!