Screen randomly shuts off on an old iMac 27in
I am posting a self-answered question to help anyone for an issue I spent several days looking for a solution for, and finally found one.
I had an old non-supported iMac 27in that had the screen shutting off for no apparent reason after some time ranging from a 30 minutes to a few hours to sometimes days. I tried for months to find a pattern, but with no success. My only solution was to reboot the device during this time.
The machine would still be running perfectly, just the screen would not come back no matter what.
I followed all the Apple official and other non-official guides with no success.
I finally found a consistent solution to revive the screen which I posted below. Hope it helps.