I found that in my iMac shut dowm problem occurs every time after the computer has been in Standby operation. In this mode the computer will go through about 3 hours (14400 sec) of inactivity. This help me to solve the shut dowm poblem:
sudo pmset -a autopoweroff 0
sudo pmset -a autopoweroffdelay 86400
To restore initial data use:
sudo pmset -a autopoweroff 1
sudo pmset -a autopoweroffdelay 14400
To see all power system data use:
For more informatiom see:
https://discussions.apple.com/thread/4512384?start=0&tstart=0
and
https://www.garron.me/en/mac/macbook-hibernate-sleep-deep-standby.html
"autopoweroff - Where supported, enabled per default as an implementation of Lot 6 to the European Energy-related Products Directive."