When you click to turn off the computer, Windows sends a message to all running applications to tell them to close. In response, they should tidy up and close.
Some badly written applications don't respond correctly to the message, other srespond as though you had manually elected to close them, and attempt to show a message (such as "Are you sure?", or "Do you wish to save changes?"). Yet others need to do some tidying up which may take a few seconds.
As you haven't said which task bar icons remain open, it's difficult to diagnose your problem to any greater depth. Also, as you say that Windows closes without a problem the second time that you click close, it's possible that it would have closed anyway, given a few more seconds.
One way to diagnose the application that's causing your problem would be to close one of the system tray icons manually, then click "Turn off". If that makes no difference, work your way through each of the system tray icons one at a time, each time closing the icon, then attempting to close turn off. Eventually you should be able to locate the specific app that's preventing the normal shutdown.