In the pursuit of happily-ever-after, the odds seem to be stacked against us.

Men and women reap huge benefits when they stick around with a good partner -- staying happier and healthier, living longer and passing along more genes. But the sticking-around part is a challenge. We don’t get long-term relationship payoffs right away. And until then -- between the once-upon-a-time and the happily-ever-after -- plenty of temptations can beckon.

Not that it’s wrong to shop around before settling down. But there always will be enticing alternative mates -- whether heart-grabbing or merely eye-catching. So researchers wonder: With so many attractive alternatives, how do humans manage to maintain relationships at all?

The brain appears to have some tricks up its neural sleeve. A new line of research is exploring how automatic psychological mechanisms kick into action when the eye starts to wander, helping resist temptation and strengthening the relationship -- even without us being aware of it.

Here’s a sample from some recently published experiments (all on heterosexual men and women in committed monogamous relationships) that show how our brain keeps us connected to -- and, yes, even happy with -- the old ball and chain.

(Spoiler: When it comes to relationships, men and women are a bit different.)

Subconscious alarm bells

An early-warning alert system signals threat.

In an experiment published in the Journal of Personality and Social Psychology in July, researchers at McGill University in Montreal asked 150 men and women to imagine chatting with an attractive member of the opposite sex. For comparison, another 150 imagined boring encounters with people of the same sex. After the visualizations, all participants played fill-in-the-blank word games designed to reveal subconscious thoughts.

When presented with “THR_AT,” for instance, women who’d thought about hunky men tended to write “threat.” But men more often wrote “throat.” Likewise, given “LO_AL” after the hunk visualization, women saw “loyal,” but men tended to see “local.” (Men and women who imagined ho-hum encounters answered similarly, so researchers decided the differences were because of imagined flirtation.)

The conclusion? The mere thought of an outside flirtation is enough to trigger alarm bells in women’s brains -- but not so much in men’s. “It’s an amazing outcome,” says John Lydon, professor of psychology at McGill University and leader of the study. “The same things weren’t coming to mind for the men.”

Extra tolerance

A flirtation can trigger increased niceness toward a partner -- or not.

In this experiment, the McGill researchers upped the ante. Each participant encountered a live temptation: a good-looking actor of the opposite sex, trained in the art of subtle flirtation (and pretending to be another participant signed up for the same study). A comparison group included aloof fake subjects who made no conversation.

After interacting with the beautiful actor, participants were then asked to imagine how they would react if their own partner were to act not-so-beautifully -- being late for a date, for instance, or lying about going out with friends.

Men who were paired with the chatty attractive woman were less likely to forgive their girlfriends’ hypothetical bad behavior (compared with men paired with the taciturn fake participant). Women, on the other hand, did the opposite: Those who had interacted with the good-looking man were more likely to be extra forgiving and make excuses for their boyfriends’ slip-ups.

The conclusion? Subconsciously, men saw the flirtatious woman as a good alternative mate and so felt a bit less committed to their girlfriends. Women, too, saw the friendly guy as an attractive alternative -- but they also saw the threat he posed. So women tried to strengthen their relationships -- essentially pitching in to do more of the “heavy lifting” of relationship upkeep, Lydon says.

Avoidance

Sometimes we mentally push away temptation.

Here the McGill researchers turned to computer games. They asked 115 men and women to explore an immersive virtual reality and play with the position of images dangling in space: photographs of animals, fruit and attractive people.

Women who had been first primed to think subconsciously about their relationships tended to shove away the images of the handsome men. The male participants, on the other hand, didn’t push away the good-looking women -- if anything, they pulled them closer.

Women may automatically know how to protect a relationship better than men do, Lydon says. So the researchers tried to teach men’s subconsciousness a new trick: planning ahead for temptation.

Studies have shown, for example, that New Year’s resolutions succeed more often when people first form a plan of behavior for specific situations. So the researchers had another group of men visualize a scenario involving a cute woman at the bar and a girlfriend gone for the weekend. Then they had the men complete the following sentence in detail: “When the girl approaches, I will [blank] to protect my relationship.”

When let loose in a virtual reality building, these trained men tended to avoid certain areas: the rooms with pictures on the wall of pretty women flickering imperceptibly, flashing for only a few thousands of a second -- so fast that only their subconscious would notice. Untrained men, however, virtually flocked to the flashing-women rooms.

The conclusion? Women already know how to distance threats and protect relationships, perhaps because they’ve been taught to do so by society. “Men don’t have those strategies built in,” Lydon says, “but they can be trained.”

What’s more, the methods can be automatic. “These strategies don’t require conscious control,” he says, “so they can work if you’re tired or distracted, or even if you’ve had a drink.”

Suppression

We can also push down illicit thoughts.

In a set of experiments on 120 men and women, published in Evolution and Human Behavior in March, researchers at UCLA explored how love gives the brain a boost.

Normally, suppressing unwanted thoughts will backfire. You can force yourself not to think about chocolate cake for a while, but soon your thoughts will be filled with rich delicious desserts even more than usual. It’s called the ironic rebound effect, says Gian Gonzaga, first author of the paper and now a senior research scientist at EHarmony, a match-making website. And psychological theories say suppression shouldn’t succeed with thoughts of deliciously tempting men and women either.

Yet it does work. When men and women were induced to experience feelings of love for their partners, they were able to suppress thoughts about attractive members of the opposite sex. Feeling lust for their partners, on the other hand, didn’t help with the suppression.

What’s more, love induced a selective memory block. When shown pictures of attractive members of the opposite sex, the in-love participants later couldn’t remember important details -- such as whether the person in the picture had a good body or dreamy eyes. They could remember irrelevant details, however, such as whether the person was wearing a purple sweater or holding a hot dog, Gonzaga says.

The conclusion? The warm-and-fuzzy glow of love makes the unwanted thoughts go away -- either by providing a distraction or by interfering with the coding of the memory. “Love seems to cut off being able to remember anything that might threaten the relationship,” Gonzaga says. Desire doesn’t do this, though. “Love helps a person commit,” he says, “but desire fuels sexuality, and sexual desire is not about commitment.”

Inattention

Best of all, we can just not notice temptation.

In another set of experiments of 124 men and women, published in Evolution and Human Behavior in September, Gonzaga and colleagues at Florida State University found that love can induce a sort of “hottie blindness” in people.

A computer game measured how quickly participants could tear their eyes away from an image of a good-looking member of the opposite sex. The quicker the eye dart, the less captivating the image.

Participants who were feeling generally happy tended to linger somewhat on the tantalizing pictures. But folks feeling strong love for their partners seemed to be repelled by the tempting sight, and their attention skipped away relatively quickly. And a final vindication for the males: Love seems to be an especially potent charm for men, since it drove away their attention from the tempting pictures even faster than it did for women.

The conclusion? Love shapes our attention to members of the opposite sex at a very primitive level. “This must be very deeply ingrained in us,” Gonzaga says, “because it happens so quickly, and we can’t consciously control it.”

As for the gender difference in all the experiments: It may come out in the wash. “Men and women have different challenges in a relationship, but the long-term gains are powerful for both,” Gonzaga says. And both -- whether through innate ability, training or love -- are able to respond to little threats lurking in flirty smiles. “The basic idea is that if people understand that their relationship is being threatened, they are going to defend it.”