I think perhaps a simple distinction can help to answer
MichaelSomething's question while at the same time precluding unnecessary disputes. Let us distinguish between
"can" vs. "should." I
can rob a 7-11 convenience store with a loaded 9mm Springfield, but I certainly shouldn't. Right? And if I do it, there'll be some legal consequences I won't enjoy.
Okay, so
per the rules as written for 5e, the DM is basically God and
can do virtually anything he or she wants, even including blatantly overriding players' decisions and actions. Yep, the latitude for doing that is indeed in there.
But what a stupid idea. I mean, wow.
Mercurius pointed out that any good DM, like any good author, will not want to override big, unexpected narrative twists when they come up. Much of the beauty and excitement of the game comes from such twists: canceling them spoils the game. I think that's exactly right. I've had such major twists come up in my game three times now and I eagerly look forward to #4. I consider them the best parts of our Story So Far.
Can the DM prevent or "correct" these things when they occur? Absolutely, and it's very easy.
Should the DM do it? Different people have different priorities and play styles, certainly, but I'll still venture to say,
"No." If you do it, you and your players are really going to miss out.