Sometimes, for whatever reason, the Finder is doing something in the background and won't let you log out or shut down until it's done.
There's only two ways to fix this.
(1) If you're still able to browse your files in the Finder, go to your Applications folder > Utilities folder > Activity Monitor. In this application, you'll see an iTunes-like search bar in the upper-right corner. In it, type loginwindow and select the first thing on the list. Click "Quit Process" in the upper-left, and choose "Force Quit". This will log you out for sure.
(2) If you can't browse your files in the Finder, hold down the power button for five seconds, which will force your computer to shut down.