Press power button and decide what you want - Restart, Sleep, Shutdown or Cancel

In order to change the power-button behaviour, open the Terminal application (located in /Applications/Utilities), then type in the following command, followed by the return key:

defaults write com.apple.loginwindow PowerButtonSleepsSystem -bool no

After entering the above command please restart your Mac to ensure this new preference is loaded into the system.

Once entered and restarted, press the power button on your Mac for a second or two, a window will pop up to specify whether you want to sleep, restart, shut down, or cancel. No longer will your Mac choose to sleep automatically.

If you decide not to have your Mac to do this, then you can easily reverse the command by opening the Terminal and typing in this command:

defaults write com.apple.loginwindow PowerButtonSleepsSystem -bool yes