New York City was shocked on Tuesday when mayoral candidate Anthony Weiner admitted that in 2012 he engaged in racy online conversations and sent explicit photos to a woman -- a year after he resigned from Congress because of similar misbehavior and promised to change his ways.

Weiner's confession, forced by a website that published details of his dalliance, is threatening to derail what to this point had seemed like one of the most remarkable political comebacks ever.

The candidate, who was narrowly leading the Democratic mayoral field by three points in a July 15 Quinnipiac University poll, insists he's staying in the race, despite calls by newspaper editorial writers for him to drop out.

Politicians Who Bounced Back: Photos

"I hope  are willing to still continue to give me a second chance," he said at a news conference.

So far, the public has been willing to do that. Quinnipiac found that more than half of Democratic primary voters thought it was OK for Weiner and former Gov. Eliot Spitzer, another candidate with sexual indiscretions in his past who is running for city controller, to seek office again. But will they forgive Weiner yet another time?

Quite possibly, yes, if psychological research about the nature of forgiveness and studies of public attitudes about politicians' private morality is any guide.

"Americans have an amazing depth of forgiveness for politicians," says Frank Farley, former president of the American Psychological Association and a Temple University psychologist who studies political behavior and human emotions.

He notes that there are plenty of leaders whose reputations survived sex scandals, from former President Bill Clinton to former South Carolina Gov. Mark Sanford, who left office in 2010 after admitting to an extramarital affair, only to resurface this year and win election to Congress.

"Look at Clinton," Farley says. "He managed to land on his feet, and he's now probably the most popular politician in the world."

Truth or Lie: How to Tell: Photos

Our brains have been wired by evolution with the capacity to forgive. A 2001 study by British researchers, who watched subjects' brains with MRI scanners, found that forgiveness is a complex activity that involves multiple parts of the brain, in particular the posterior cingulate gyrus deep inside our brains. We learn to use that equipment.

"The evidence is clear that forgiveness can be taught," Farley said.

And to an extent, we may be programmed to forgive and forget. A study by University of Chicago behavioral scientist Eugene Caruso, published in the Journal of Experimental Psychology General in 2010, found that we're more likely to view future misdeeds more harshly than identical transgressions that have occurred in the past.

In Caruso's experiment, subjects were more upset when they learned that a cold drink vending machine automatically would raise prices the following month when the weather got hot, compared to another group who was told that the machine had been set to do that in the past.

We have a tendency to forgive, even though it may not always be in our interests. In a 2010 study, Florida State University psychology professor Jim McNulty found that newlyweds who reported that they'd forgiven a spouse for a transgression on a particular day were 6.5 times more likely to report the following day that their partner had done something negative again.

In other research, McNulty found that those who forgave partners who habitually behaved badly tended to feel worse over time. Forgiving people who did bad stuff, he concluded, didn't necessarily improve their behavior.

Indeed, we seem to hold politicians by a looser standard than people we actually know intimately, such as our own spouses.

A 2008 Gallup poll found that 64 percent of Americans wouldn't be able to forgive their husbands or wives for infidelity, compared to 33 percent who would. Interestingly, though, only 36 percent of Americans say that if they were married to an elected official, they would stand next to the person on a podium while he or she was answering questions about an affair, as Weiner's wife Huma Abedin did on Tuesday.

Anthony Weiner, a leading candidate for New York City mayor, answers questions during a press conference on July 23, 2013 in New York City. politics, scandal, come back

One reason why politicians have a chance to survive sex scandals is that Americans don't seem to consider them as serious as other sorts of misdeeds, and often draw a distinction between private morality and public conduct.

A 2011 scientific survey conducted by the Public Religion Research Institute, for example, found that 87 percent of Americans think elected officials who took bribes should resign, while only 55 percent say that those caught patronizing prostitutes should quit. And 44 percent of Americans believe that a politician who commits an immoral act in private life can still behave ethically in office, exactly the same number as those who think that a marital cheater can't be trusted with their tax dollars.

Majorities of men (51 percent) and people of both sexes under age 35 (54 percent) think it's possible for a politician with a sleazy personal life to be honest and trustworthy as a leader.

NEWS: Practice Makes the Perfect Liar

It also probably helps to call a press conference and ask for forgiveness from the public, as Weiner has done.

A 2009 study by accounting professors Rick Warne of George Mason University and Robert Cornell of Oklahoma State University found that civil juries were less likely to hit business defendants with negligence verdicts if they acted contrite -- even if they didn't actually admit any wrongdoing.

But there's a catch: A study by researchers at several universities, published in 2011 in the journal Organizational Behavior and Human Decision Processes, found that participants in a role-playing business game who'd been cheated were more likely to regain their trust if a wrongdoer seemed truly repentant.

"We want to know that the person has changed somehow, that their character has changed," one of the researchers, University of Southern California associate professor of management Peter Kim, explained in a Science Daily article.

"We found that it comes down to the three Rs," explains one of the study's authors, Kurt T. Dirks, senior associate dean and professor of managerial leadership at Washington University's Olin Business School.

NEWS: Goose Bumps Never Lie

"You have to show regret, be able to provide a statement about reform -- that you're going to try to fix these personal shortcomings -- and also resolve, that you're going to act differently in the future. To have a potential to regain others' trust, you have to have all three."

Dirks says that while people are less inclined to forgive character flaws than incompetence.

"With character, that question mark -- 'Can I really trust this person again?' -- is always going to be in their minds," he says.

But paradoxically, research about organizational behavior also shows that people are willing to overlook a leader's moral imperfections, so long as the person continues to provide them with something that they value. For a CEO, that might mean profits and rising stock values, while a politician who's skilled at getting funding for new roads and at bringing lucrative government contracts to his district may similarly get the benefit of the doubt.

The downside: That sort of loyalty only lasts as long as the results. "We see that with sports coaches all the time," he explains. "Everybody thinks that guy is slimy, but as long as he wins, he's going to keep his job."

But as Weiner and Spitzer may discover, even the public's willingness to forgive may have its limits.

In a just-published study, University of Connecticut researchers Rodrigo Praino and Vincent G. Moscaro, and their University of Ottawa colleague Daniel Stockemer, found that voters are surprisingly willing to reelect Congress members who become embroiled in ethics investigations if they chose to run.

Between 1972 and 2006, they found that 49 percent of them were returned to office despite the allegations, compared to 25 percent who were rejected by voters. Another 26 percent either retired or resigned. Even so, political incumbents suspected of wrongdoing still didn't do as well as their untainted Congressional colleagues, nearly 87 percent of whom were reelected.