I am so glad that someone asked this question, Bob (cool name by the way). This question is really about one of my favourite topics, the cycle of choice.
What you are trying to do is steer the reader through a process of a character making a choice that is unexpected. This process has four steps.
- Emotion
- Logic
- Anticipation
- Action
Out of character actions are driven by two factors – emotions and anticipation of the outcome.
We start the scene with the emotional reaction to the events that have gone before. For example, if the best friend was just shot dead emotions might be shock and grief. These emotions may, or may not, cloud what comes next. They will certainly colour it.
Then, after the emotional dust has settled – perhaps as soon as a paragraph later – we get to logic. In our example, the character has just seen their friend shot. They ducked in reaction but now they have to think about what to do next. Our character is a brave hero and we expect them to fight back. They think logically about the next steps. Gun ready, they think logically about where the shooter is.
Then comes anticipation. This is coloured by the grief and shock at the loss of a friend. They anticipate death, they realise that the news they are carrying will be lost. They imagine that the mission will fail.
Instead of attacking, which we would expect, they look around and, seeing an exit, they leg it.
What we did was talk the reader through the steps of thought that went from brave soldier to running away.
You can apply this process to any character and if the emotional, logical, and anticipation parts line up to justify an apparently out of character moment, the action seems logical.
Of course, our brave hero will have to deal with the shame of running away and that may colour and drive the rest of the story.
I hope that helps.