What works for me perfectly since almost one year is simply to set the brightness of the screen to maximum and disable the automatic brightness control (I don’t know how it’s exactly called in english, I’m translating directly from german. However it’s the checkbox below the slider for brightness).
I have an iMac Mid 2011 and the problem of the screen randomly going black occured a year ago. It went black but the iMac was still working, like when I had music on it still played. I couldn’t awake the screen with my keyboard or mouse, only by pressing the power button for short and then the iMac went into silent mode and then pressing the power button again the screen came back, but very often only for a few minutes before it got black again.
I was doing a very hard research over two days and tried everything recommended. Finally the above described solution by setting the brightness to maximum worked for me (I’ve also read that for some dimming the brightness works). Since then the screen doesn’t go black anymore. I sometimes got anxious when I accidently touched the dimming key on my apple keyboard, like when I removed dust from the keyboard and the screen went black again. Fortunately I understood what has happened and set the brightness to maximum again. I can’t explain what exactly is causing this issue, if it’s a software bug or some dust covering a sensor inside the Mac. I guess there are also different reasons for the screen randomly going black and it might not work on every Mac, but give it a try.
What I’ve recently read and makes sense to me, is that some sensors (like for temperature) are covered with dust, don’t work properly and are causing the screen to go black. Try to clean the inside of your Mac with compressed air, before you hand your Mac to the Apple store for reparations.