Repeat this mantra to yourself: "Overcoming a challenge doesn't have to mean winning a battle."
A challenge can be a social interaction. Exploration. Traps in a dungeon. And sometimes it's simply getting out of overwhelming odds alive, even if that means running away.
One of the great traps in DMing is getting trapped in binary thinking when it comes to encounters. "Do they do X, or do they suffer Y?" should never be the only options you consider. Plan for W, Z, A, B, and Octopus. And by that, I mean plan for options you didn't consider that are perfectly logical, and have a few ideas for what to do in case they do something utterly bizarre that you could have never planned for.
And don't be afraid to, sometimes, just toss your plans in the air and roll with whatever insanity the PCs have done this time. Have they decided the evil sorcerer makes more sense than the good king they were hired to back? Go ahead and have him be the greater good. Maybe even have the entire campaign be his path toward redemption.
Also, be prepared for when the dice decide to do strange things with how they interact with the rules and your house rules. Do you have a house rule that rolling a 20, then another 20 to confirm, then a third 20 to confirm that is an instant kill? Ask yourself what will happen the first time that comes up while fighting a god. My first character, way back in 3E, killed Vecna by kicking him the crotch this way.
Most of all, try to be flexible. It's entertainment. Not a recreation of history.