Since OS X 10.9 mavericks, the behavior of the power button has been changed. When you press the power button for about 2 seconds, it will put macOS (OS X) in stand-by (sleep) mode.
With the following command you can use the power button function as in previous versions of OS X. By showing a dialog box for turning off the Mac and more.