Bernie Sanders says that Hillary Clinton’s explanation of her husband’s decision as president to sign legislation banning same-sex marriage is bogus. And he has a point.

At issue is the Defense of Marriage Act, which passed Congress with overwhelming bipartisan majorities at the height of the 1996 presidential campaign, when Bill Clinton was seeking a second term. It’s now a relic of history, thanks to a Supreme Court ruling earlier this year, but the fact that Bill Clinton signed it in the first place has long infuriated gay rights supporters.

On “The Rachel Maddow Show” last Friday, Hillary Clinton said her husband had been trying to head off a more dire legislative response. “There was enough political momentum to amend the Constitution of the United States of America,” she said, “and that there had to be some way to stop that.” DOMA, she said, “was a line that was drawn that was to prevent going further.” This is the same explanation Bill Clinton offered when he formally reversed his position on gay marriage two years ago.

Sanders, who as a House member in ’96 was among the few lawmakers who voted against DOMA, is now hammering Hillary Clinton for her statement, arguing that the idea of a constitutional amendment prohibiting gay marriage wasn’t on the radar back then. At last weekend’s Jefferson-Jackson Dinner in Iowa, he suggested that she’s “trying to rewrite history,” and in his own appearance on Maddow’s show Monday night he said, “[Y]ou can’t say that DOMA was passed in order to prevent something worse. That is just not the case.”

RELATED: Hillary Clinton on reversing her husband on civil rights

That’s basically accurate. It wasn’t until 2002, a year into George W. Bush’s presidency, that a marriage amendment was first introduced in Congress. Why the delay? Because in ’96, the concept of same-sex marriage was new and exotic and public support was minimal, even in left-leaning states. A California poll that summer found that just 30% of voters favored allowing unions between couples of the same gender. The only reason the issue was even on the table was because a state Supreme Court ruling in Hawaii had raised the theoretical possibility that that state would be compelled to allow gay marriages. DOMA was conceived as a preventive measure – if it did become legal in Hawaii, no other state would be forced to recognize a same-sex union. The assumption was that DOMA would be more than sufficient to stamp out the threat of gay marriage.

It is true that several lawmakers who voted for DOMA in ’96 later recanted their support and, like the Clintons, claimed they had been trying to forestall a constitutional amendment. And it is certainly possible that heading off an amendment was at least part of Bill Clinton’s calculation when he signed DOMA. But that wouldn’t explain why, upon signing it, he began airing ads on Christian radio stations touting his effort to fight gay marriage. Clearly, there was more going on here – a lot more.

The way Sanders tells it, Bill Clinton is guilty of political expediency. Gay rights weren’t a majority issue in ’96 and he was due to face the voters that fall, so he opted to swim with the tide – while Sanders instead opted to make a lonely and principled stand. “What the American people and Democrats have to know,” Sanders said Monday night. “Which candidate historically has had the guts to stand up to powerful people and take difficult decisions?”

RELATED: Sanders draws sharpest contrast with Clinton yet

But Sanders isn’t telling the full story on Bill Clinton and gay rights. Because to understand what Bill Clinton did in 1996, you first need to remember what he did in 1993. That was the first year of his presidency, and one of his first moves after being sworn-in was to fulfill what had been a bold campaign promise: to end the military’s ban on openly gay service members. But the new president was met with fierce resistance – from revered military leaders like Norman Schwarzkopf and Colin Powell and from leaders in his own party, most notably Georgia Senator Sam Nunn, the Democrats’ point man on defense issues.

Public opinion swiftly turned against Clinton, who was accused of trying to use the military for “social engineering.” He was also pilloried for focusing so much political energy on what to many Americans seemed like a niche issue. Further complicating matters was Clinton’s own service history. Allegations of Vietnam “draft-dodging” had dogged him in the 1992 campaign and hard feelings remained among some military leaders and veterans groups. When on Memorial Day 1993 Clinton appeared at the Vietnam Veterans Memorial in Washington, he was greeted with boos and turned backs.

Clinton’s push to end the ban stalled, his poll numbers plummeted (Time dubbed him “The Incredible Shrinking President” that June), and he was forced into a compromise on the issue – the “Don’t Ask, Don’t Tell” policy that wasn’t rescinded until 2010.

In short, Bill Clinton went out on a limb for gay rights three years before he signed DOMA – and his presidency nearly collapsed because of it. “Gays in the military” was one of the reasons for the Republican wave of 1994, when the GOP grabbed control of the House for the first time in 40 years. In the wake of that midterm election, Clinton was left for dead politically, urged even by members of his own party not to seek a second term in 1996.

Yes, by the time DOMA landed on his desk in September 1996, Clinton had recovered his standing and was coasting to victory over Bob Dole. More than likely, he could have vetoed the bill and still won the election easily. (Any veto, by the way, would almost certainly have been overridden by Congress.) But that’s easy to say now. In that moment, it’s not hard to imagine Clinton’s rationale going something like this: I came so close to losing my presidency and it’s practically a miracle that I’m in the shape I’m now in – do I really want to risk stirring up a repeat of the “gays in the military” debacle right now and give the Republicans their best (and probably only) shot of winning? Is it worth the risk of giving the GOP total control of Washington – the presidency, the Senate, and the House – and a chance to push through their entire agenda (which would include plenty of anti-gay measures)? Over a bill that’s going to become law no matter what?

A profile in courage moment? Hardly. But a coldly rational judgment from a politician who had gotten too far ahead of the public on gay rights and paid dearly for it? You could make that argument – unless, of course, your name is Clinton and you’re running for president right now.