Macbook Pro turning off in sleep mode

Solution 1:

My iMac began shutting down at random in sleep mode. As it was 6 years old I assumed that the power supply was packing up causing overheating and shut down.

Was about to rush out and buy a new one but had a specialist look at it first. It turned out to be software, freebie malware and avast. Once removed machine runs fast,like new, and doe not shut down. Object lesson look before you leap!