First and foremost. Staying hydrated is the most important thing when working long hours. You will feel drastically better if you take sips of water every so often. This will keep you from feeling bloated and full, help you avoid running to the bathroom every 15 minutes, and you won’t feel as light-headed. Staying hydrated means staying focused.
Take breaks. Every so often, get up and walk around. Get some fresh air or a cup of coffee. Chat with a friend for a minute. Take a bathroom break. Even just looking away from your work for a minute (especially if you work on a computer screen) will help you feel less drained. Any small break that is acceptable for your office will do, so long as you are moving. Adjust your posture to avoid feeling stiff and tiring yourself out further for no reason.
Conserve your energy. Do not over-exert yourself if you know you have a long night ahead of you. Pace yourself with your work so you will not burn out. It is better to be a steady worker than to work in one big spurt and then lose your momentum.
Know when to stop. At a certain point you will no longer be productive. You will get tired. You will lose focus. As the night goes on, you will become slower and less accurate. Even if you are not finished with your work, sometimes it’s best just to call it a day and tackle in the morning when you’re feeling fresher.