How does an idea get into a president’s head? Trace back the story of President Obama’s big idea this week — that two people of the same sex ought to be able to marry — and you end up someplace unexpected.

Like Oklahoma. About 1966.

That was before the Stonewall riots in New York City. Long before homosexuality was removed from the American Psychiatric Association’s list of “mental disorders.”

In the college town of Norman, a young Air Force veteran named Jack Baker asked a librarian named Michael McConnell to form a committed relationship. McConnell said yes.

With one condition.

“He made me promise that we would wed legally,” Baker recounted recently.

That promise helped start a slow, shuddering change in American politics: 46 years later, a president said on television what McConnell and Baker were once ridiculed for saying to each other. Not just that gay couples might want to marry — but that such a thing might be legally possible.

It was not just a wish, in other words. It was a goal. In 1970, in a case that made national news, Baker and McConnell applied for a marriage license in Minnesota.

“Most marriage laws across the country — state laws — did not specify the gender of the parties getting married, because it was unthinkable” in 1970 that anybody but a man and a woman would apply, said George Chauncey, a history professor at Yale University.

After Baker and McConnell and a few other couples tried, he said, “the idea had suddenly become thinkable.”

Now, same-sex marriage seems likely to be one of the dominant social issues of the 2012 campaign season. On Tuesday, voters in North Carolina passed a constitutional amendment to ban it. This fall, bills relating to same-sex marriage will also be on the ballot in Minnesota and Maine. In Maryland, opponents of a new law allowing same-sex marriage are hoping to force a public vote on it.

The shift in this debate — from the fringe of the gay-rights movement to the center of American politics — was clear this week, both in Obama’s endorsement and the reaction of presumed opponent Mitt Romney.

Obama presented his views not as cutting-edge but as slightly overdue. He said he began to support same-sex marriage after hearing from military personnel and others who supported it.

“It is important for me personally to go ahead and affirm that same-sex couples should be able to get married,” Obama said in an interview with ABC’s Robin Roberts.

Romney, the likely GOP nominee, said he still believes that marriage should be only between a man and a woman. But he said he did not object to gay couples adopting children and said he would be open to states providing some rights to same-sex couples.

Numerous defeats

Before now, the biography of this big idea has been dominated by its defeats.

Baker and McConnell were denied when they applied to marry in Minnesota in 1970. They challenged that decision in court. They lost.

“The institution of marriage as a union [of] man and woman, uniquely involving the procreation and rearing of children within a family, is as old as the book of Genesis,” wrote the Minnesota Supreme Court. The U.S. Supreme Court declined to step in.

In the years after that, the AIDS epidemic altered the way America viewed gays and the way that gays, as a community, viewed themselves. The country had seen gay couples as couples, struggling with sickness and grief.

And many partners had found themselves treated as legal strangers, kept outside hospital rooms and medical decision making.

“Until that point, government had been the problem. And if we could just get the government out of the bedroom, so to speak, gay people would be able to lead their lives in relative peace,” said Carlos Ball, a professor at Rutgers School of Law-Newark.

A change in strategy

But after the AIDS epidemic, there was a shift: Instead of keeping the law away, gay couples wanted the law on their side. “This request for marriage is, in effect, sort of asking the government to regulate our relationships, or at least give gay people the opportunity to be regulated by the government,” Ball said.

Then, in Hawaii, a lesbian named Ninia Baehr had an ear infection. She lacked health insurance and — as medical bills piled up — she called a local gay rights group to see if she could obtain insurance through her partner.

They asked if she’d like to get married, instead. When the state of Hawaii refused her request for a marriage license, Baehr and others filed suit. Their case brought a landmark victory in 1993: State courts declared that Hawaii had no constitutional basis for denying marriage licenses to gay couples.

Then the case led to one loss after another. Hawaii amended its constitution and defined marriage as only between a man and a woman. And, around the country, some religious and conservative groups began to mobilize against a threat they hadn’t taken seriously before.

“It’s a mistake to look at the desires, or even the needs, of individual same-sex couples,” said Peter Sprigg at the Family Research Council, a conservative group that has led opposition to same-sex marriage. “What we need to be looking at it is the needs of society, and what type of relationship serves this unique purpose of procreation.”

The result was the 1996 Defense of Marriage Act, signed by President Bill Clinton. It defines marriage, for federal purposes, as a legal union between one man and one woman. The Obama administration has now stopped defending that law in court.

For those advocating same-sex marriage, the next big win came in Massachusetts in 2003, when the state Supreme Court legalized marriages between gay couples.

Now, six states and the District of Columbia allow gay couples to marry. Two states, Washington and Maryland, have gay marriage laws that have not taken effect. And five others give gay couples the rights of marriage without the name, allowing “civil unions” instead.

But, in 39 states, gay marriage has been specifically prohibited through laws or constitutional amendments.

Baker and McConnell, the men who made the promise in Oklahoma, still live in Minnesota, well past retirement age. They now avoid the media: When a Washington Post reporter called McConnell this week, he declined to comment.

They have seen up-close that making same-sex marriage thinkable is not the same as making it real. Gay marriage is still illegal in Minnesota. And this November, voters will consider writing that ban into their state constitution.

Staff writer Ned Martel and staff researcher Lucy Shackelford contributed to this report.