An alternative to shocking your reader with a surprise ending is to build tension and relieve it. Let me illustrate both methods.
Shocking your reader means to detonate a bomb your reader never knew was ticking. It is unexpected, and so what precedes it is likely boring or irrelevant to the ending. Film is abundant with examples where writers chose to abandon expectations in favor of shock value, but picture books also make this mistake.
Many writers will choose to shock their readers because they don't want to play into expectations, but sometimes that is precisely what you should do. Let the bomb tick and resolve it after the tension has built.
Another way to look at it is like blowing up a balloon. Everyone knows what happens when you overfill a balloon, you can see it coming, and it still makes you jump.
A great example is *I Want My Hat Back* by Jon Klassen. Jon establishes the problem on the first page and shows the reader where the hat is early on. The rest of the story builds tension.
I am not saying that you can't ever subvert expectations, but the twist needs to have a reason for existing. My favorite example is *Hungry Hen* by Richard Waring and Caroline Jane Church. A fox patiently watches and waits for a hungry chicken to grow plump. As the story goes, the hen gets bigger and bigger, just as the fox wanted. However, bigger is not always better.