If you can access a terminal use
sudo poweroff. You can access a TTY by pressing Ctrl+Alt+F1; TTY is just a terminal. You can return to the graphical desktop by pressing Ctrl+Alt+F7.
Otherwise you can use kernel interupts to safely shutdown the computer:
Ctrl+Alt+Print Screen+R,E,I,S,U,B (Hold down Ctrl, Alt, and Prnt Scrn then press REISUB in that order with about a second pause between each letter)
The keyboard has to be plugged into the computer you want to shut down. The command above will restart the computer. Unfortunately, it's not so easy to just power-off this way. Hit the power button after the computer restarts to keep it from rebooting all the way.