The trigger could be an opportunity attack, and the Action could be casting the mage armor spell, e.g.For example:
Alberich the Absent-minded is moving towards the evil lich Xanax to put a leather bag over its head. Xanax' skeleton minion attacks him in passing with an opportunity attack. Alberich has not used his action yet. He stops his movement to cast a quick mage armor on himself, which he forgot to do in the morning.
To clarifyIt is not only about opportunity attacks. Other triggers would be possible, thislike casting dimension door to get away from dropping into a pit trap.
The question is not about being able to take the Ready action, that allows you to take a premeditated Action in response to a trigger. It is not just about opportunity attacks, eitherclear that you can do that. Other triggers would be possible, like casting dimension doorIt is about spontaneously deciding to get away from dropping into a pit traptake the Action.
Background
(You can skip this, it is not necessary to understand the question).
This question is came from this other question, asking about taking bonus actions in response to triggersin response to triggers on your turn. I argued that you could not take an Action, hence you could not take a bonus actionBonus Action. Then I thought: how do I know you cannot take an Action?
I tried to answer this, and in spite of being convinced that it should not be possible, was not able to find explicit support in the rules. The best I could come up with it that the very existence of reactions shows that you should only be able to take Reactions in response to a trigger. But there are many other reasons for the existence of Reactions, like the Ready action or like actions outside your turn, so this is a somewhat shaky argument.
I am therefore looking for help here. You can skip the following background work, it is not part of the question itself.
Reactions
A reaction is an instant response to a trigger of some kind, which can occur on your turn or on someone else’s.
It is clear that you can try and take a reaction in those cases, although it is less clear if it would be able to prevent the trigger. Reactions actually have language explaining how they are resolved relative to the trigger:
If a reaction has no timing specified, or the timing is unclear, the reaction occurs
after its trigger finishes,
So for a normal reaction, what you do would be too late. Reactions have all this text on when you exactly can take them.
Actions
In contrast, I was not able to find an explicit statement about timing for actions, that says you cannot take an action in response to something that is happening on your turn like you can take a reaction. There are no restrictions on when during your turn you can take your action in the text. All the PHB has on page 189f is
On your turn, you can move a distance up to your speed and take one action. You decide whether to move first or take your action first. (...) You can forgo moving, taking an action, or doing anything at all on your turn. (...) You can break up your movement on your turn, using some of your speed before and after your action (...) If you take an action that includes more than one weapon attack, you can break up your movement even
further by moving between those attacks