You Only See It in Hindsight
You never realise you are jeopardising your life in the moment you are doing it. You have no context, while committing the act, that this very act would prove fatal. There is no way to determine that in advance. A person in an inebriated state never realises that this state would become permanent. That he would crave this very state every day, and that craving would destroy everything else in his life.
All forms of realisation are acts of hindsight analysis. All of your understanding, therefore, exists only in hindsight. You are running an algorithm of values and principles once the act has already passed. The person at the party trying the new drug knows it could prove fatal to his sobriety, and yet he continues to indulge. A man with a devoted wife and family keeps falling for the woman he met online, thinking she would restore the lost spark in his life.
All of these moments sound simple, and yet while we are living through them, our defenses are so lowered that we seldom notice we have crossed the line. One way to guard against this is to stay aware of your thoughts. When you practice awareness, you become more mindful of your thoughts, of your surroundings, and of your thoughts in the context of those surroundings. You recognise when you are tempted toward a thing, or a person, that you should avoid.
Rationalisation is not a reliable weapon here, but the fact that a conundrum surfaces in the mind is itself a sign, a sign that you would at least recognise the next step as ethically wrong. And that it carries its own set of consequences you might not be prepared to handle. Practicing awareness doesn't require meditating every day, though that helps too. All it truly requires is staying mindful of your emotions in relation to your environment.
Another approach that has proven effective is building decision-making frameworks. Once you are aware of your temptations, and even when you aren't, you can always run every decision through your internal framework. This is easier to build than it sounds. Weigh every choice against its long-term and short-term consequences.
Before you give in to temptation, ask yourself two things: what are its short-term consequences, and what are its long-term ones? The short-term consequences might be nothing, just the pleasure of indulgence. The long-term consequences could be devastating, the unraveling of your mental balance, your home, all for ten minutes of pleasure. That puts everything in perspective.
It forces the tough question: do you want something so badly right now that you are willing to sacrifice your long-term happiness for it? Ask yourself what would happen if you resisted. Would you actually miss out on something worthwhile? Do this enough times, and you will eventually build a muscle that makes you more resilient against the pull of temptation.
Self-awareness makes you conscious of your thoughts against the backdrop of your environment. Decision-making frameworks give you enough concrete reasons to resist. Use them wisely, and you will always feel in control against temptation.