Running a role-playing game is a complicated process, and no simple answer will always apply.

Relevant approaches from my Rules for DMs:

19. The players do not have the right to screw up the game. They do have the right to screw up your plot. Don’t confuse the two.
a. Do not give them a set of options that includes screwing up the game.

38. When the players come up with something you never considered, stop and think. This is the source of your absolute best, most perfect moments. It’s also where all scenario-destroying mistakes come from. Ask yourself which it is before you react.
a. “Scenario-ending" and "scenario-destroying" are not (necessarily) synonyms. You may have planned a major battle in front of the Black Gate. But a PC ending the quest by throwing the Ring into the Cracks of Doom could still be a satisfying, if abrupt, ending.

43. You will make mistakes – lots of them. A crucial skill to be a good DM is the ability to fix mistakes as quickly and seamlessly as possible.
a. This will sometimes involve admitting them. It will also sometimes involve keeping the players from ever seeing them.
b. In either case, the point is to make the game go forward, not to repair your ego.

Since the same answer won't always work, here are several specific examples.

1. Ideally, restricting their choice should occur in advance. If I don’t want them exploring the cave complex yet, then there shouldn’t be an entrance available to them.

2. Next best, when they start to do something you didn’t expect, is straightforward honesty. “Umm, I really didn’t expect you the attack the king. He is a source of lots of potential quests, and you’ll get more treasure, and more experience points, if you listen to him and work for him than if you attack him now. For one thing, you’ll lose; you really aren’t powerful enough for this.”

3. Make clear what your personal abilities are. “Hey, guys, I’m no good at running PvP. Could you all work together for this campaign?”

4. Tell them the real reason. “Guys, I have some ideas for adventures in the mountains, but I haven’t written them yet. Would you mind exploring the forest instead? Otherwise, it’s just going to be random encounters all evening.”

5. Explain the disconnect between their proposed action and your plans for the campaign. “I’m willing to spend my time and energy creating a world for you to be heroes in. I’m not willing to do it to provide a place for you to be villains. If you want to torch the village, then we need to find another GM, because I’m not comfortable running that kind of adventure.”

6. In a humorous vein, consider self-serving mendacity disguised as unselfish and brutal honesty:

“Guys, I designed this world, and I’m the only one who knows what your choices now will lead to. From where you are, the most obvious paths lead to:
A. a kobold village with copper pieces that would have been a fun adventure when you were first and second level,
B. A deadly swamp with quicksand and an Evil High Priest’s castle that will be a great adventure for you when you have about five more levels,
C. A city of Stone Giants that will make a great adventure for you in ten levels, and
D. A level-appropriate encounter with some really good loot, which could help you against an EHP and some giants.

Do whatever you want — you’re the PCs. But I recommend that you go east.”

(Then you have five levels’ time to design a swamp, and ten levels’ time to design a giant city.)

[No, I’ve never done this, and wouldn’t. I just think it’s funny.]