WASHINGTON — Ten months into his term as Massachusetts governor, Mitt Romney was abruptly confronted with an emotionally charged issue: The state’s highest court ruled that gays had the legal right to marry, thrusting the state into the forefront of the same-sex marriage debate.

Romney, now the presumptive Republican presidential nominee, faced one of the biggest challenges of his four years in office. His response would alienate constituencies on both sides and contribute to criticisms that he shifted positions for political gain, a charge renewed in his two bids for the White House. At minimum, Romney’s handling of the gay marriage ruling — laid out in interviews with key players and state documents — provides a window into his decision-making style and political tactics.

Romney had vowed while running in Massachusetts to defend and expand the rights of gays and lesbians, although he opposed same-sex marriage and civil unions. When the court ruled, he initially promised to follow its decision, while also seeking a state constitutional amendment to overturn it.

But soon he devoted his attention to trying to block the ruling. Among his moves: resurrecting a 90-year-old state law, aimed in part at preventing interracial marriage, to keep same-sex couples from flocking to Massachusetts for weddings.

The battle served to boost his national profile and conservative credentials in the years leading to his first presidential run in 2008.

To supporters, he emerged as a steadfast defender of traditional marriage. But critics and some onetime allies believe that Romney’s national ambitions — and a resulting need to tack to the right — eventually drove the way he dealt with Goodridge vs. Department of Public Health.

“He needed issues that would help him pivot,” said Rich Tafel, who founded the national gay rights group Log Cabin Republicans and advised Romney how to secure the state chapter’s endorsement in his unsuccessful 1994 Senate bid.

Tafel watched with dismay as Romney used his opposition to the Goodridge ruling to appeal to conservative groups around the country. “I think he truly does oppose gay marriage, but the speed with which he jumped on and rode that issue struck me as political,” he said.

Aides to Romney reject that judgment, saying that as governor he was motivated solely by his belief that marriage should remain between a man and a woman, and that the court was overstepping its bounds.

“His position remained constant from the very day that the decision was issued,” said senior advisor Peter Flaherty, who was Romney’s deputy chief of staff and helped craft the administration’s response. “To say that it had to do with anything other than his performing his duties as governor of Massachusetts in compliance with the law and consistent with his executive role is baseless.”

When it comes to gay marriage, Flaherty added, “I have never seen a change in tone, a change in approach, a change in purpose.”

Romney sought office twice in Massachusetts — challenging Sen. Edward M. Kennedy in 1994 and running for governor in 2002. Both times, he paired his opposition to gay marriage and civil unions with strong support for other gay rights. During the race against Kennedy, he told the Log Cabin Republicans that he would “provide more effective leadership than my opponent.” He promised to co-sponsor a federal nondiscrimination act and support efforts to allow gays and lesbians to serve “openly and honestly” in the military.

“If we are to achieve the goals we share, we must make equality for gays and lesbians a mainstream concern,” he wrote in an October 1994 letter. “My opponent cannot do this. I can and will.”

In his 2002 campaign for governor, Romney declined to back a proposed state constitutional amendment to prohibit same-sex marriage because, he said, it would also have outlawed domestic partnership benefits. At one point, after his Democratic opponent said she would sign a bill legalizing gay marriage, Romney promised to make domestic partner benefits a “hallmark of my leadership as governor,” the Boston Globe reported at the time.

Then came the Supreme Judicial Court’s ruling in November 2003 that same-sex couples had a constitutional right to marry. In its 4-3 decision, the court gave the Legislature 180 days “to take such action as it may deem appropriate.”

Opponents of same-sex marriage — citing a quirk in the state’s colonial-era Constitution that gave the governor authority over matters related to marriage — argued that the court’s decision was not binding and urged Romney to ignore it.

But Romney did not want to trigger a constitutional crisis — seeking, his advisor Flaherty said, to be “respectful of the law and respectful of people at the same time.” Initially, he struck a balanced tone with his two-track move to find a legislative solution that would satisfy the court while corralling support for a constitutional amendment banning gay marriage.

“We certainly have to follow the law, and the Supreme Court has laid down what we must do,” he said on NBC’s"Today” show the day after the ruling. “But in my view, the right action is to follow two courses at the same time.”

But the governor quickly dropped all talk about complying with the ruling. Behind the scenes, Romney advisors worked to come up with ways to head it off, according to those involved. They consulted conservative constitutional experts such as historian Matthew Spalding, who works closely with former Reagan Atty. Gen. Edwin Meese III at the Heritage Foundation.

It was soon clear that Romney could not push a gay marriage ban through the state’s liberal-leaning Legislature. So he helped persuade Republicans to support a compromise amendment that barred same-sex marriage but legalized civil unions.

It was a purely tactical move: The Supreme Judicial Court had already said that civil unions would not satisfy its ruling. But the Romney administration hoped to use the amendment — which required additional approval by the Legislature in 2005 and voters in 2006 — to persuade the court to postpone the start of gay marriages.

The maneuver failed when then-Atty. Gen. Thomas Reilly, a Democrat, declined to ask the court for a stay. Romney ultimately abandoned his support for the compromise measure, calling it “muddied,” and endorsed a separate citizens’ petition for an amendment to ban gay marriage. Still, some conservative activists criticized Romney for opening the door to civil unions.

“He was everywhere on this issue,” said C.J. Doyle, executive director of Catholic Action League of Massachusetts, a group that worked to pass the marriage ban.

As the court’s deadline neared, Romney tried another tactic: he seized upon a 1913 law that barred out-of-state couples from marrying in Massachusetts if the marriage would not be recognized in their home state.

The measure was originally drafted by the National Conference of Commissioners on Uniform State Laws — a state-backed group of judges, lawyers and scholars who write model legislation — amid national anxiety about interracial marriage, then illegal in about half the country. The African American heavyweight boxing champion Jack Johnson had recently made headlines by marrying a white socialite from Brooklyn. Soon afterward, a federal amendment to ban miscegenation was introduced in Congress.

That same year, Massachusetts — which had legalized interracial marriage in 1843 — passed the conference’s Uniform Marriage Evasion Act, a law crafted in part to keep people from skirting their home state bans on interracial marriage, said Joanna Grossman, a professor at Hofstra Law School who studies marriage regulations.

In 2003, the statute was still on the books, but had been largely forgotten until it was mentioned in a footnote in the Goodridge decision. Romney aides said there was little debate internally about the merits of using it to blunt the ruling’s effects.

“We didn’t think we were stretching the bounds of legal reasoning to apply it in this case — it was stated in the very decision that legalized gay marriage,” Flaherty said.

In late April 2004, less than a month before gay marriages were set to begin, Romney announced that the state would begin checking the residency of all couples seeking marriage licenses.

“Massachusetts should not become the Las Vegas of same-sex marriage,” he told the New York Times, a line he has repeated frequently on the campaign trail this year as he touts his efforts to stop gay marriage. “We do not intend to export our marriage confusion to the entire nation.”

The administration sent town clerks a thick document detailing the marriage laws in 55 states and territories. Romney warned that those who accepted marriage applications that violated other states’ laws would be subject to “appropriate enforcement action,” which under Massachusetts law could include fines or jail time. (Some town clerks defied Romney, but none were punished.)

David J. Rushford, the Worcester town clerk, continued to grant licenses to out-of-state couples. He said Romney used “the power of an executive office to twist the spirit of the law and to intimidate those people whose job it is to carry out the law.”

Four years later, Romney’s Democratic successor, Gov. Deval Patrick, signed a bill repealing the 1913 statute, which he called discriminatory.

Allies believe Romney’s ultimately unsuccessful efforts to stop gay marriages in Massachusetts were driven in part by a personal conviction shaped by his faith as a devout Mormon.

“It’s not just a political issue — he stands for something he believes in, his wife believes in,” said Kris Mineau, head of the conservative Massachusetts Family Institute, a group that worked closely with Romney on the citizens’ amendment to ban gay marriage. (The measure failed in the Legislature after Romney left office.)

But the issue also gave Romney a national perch. For the first time, he began calling for a federal marriage amendment and testified before the Senate about the need to “protect our societal definition of marriage.” His staff started conferring regularly with advisors in the White House and Romney became one ofPresident George W. Bush’s main surrogates against his 2004 Democratic opponent, Sen. John F. Kerry of Massachusetts.

A year later, as he prepared for his first White House bid, Romney touted his opposition to gay marriage when he addressed conservative audiences.

“From Day One, I’ve opposed the move for same-sex marriage and its equivalent, civil unions,” he told South Carolina Republicans in 2005. Calling the ruling “a blow against the family,” he said that some gay couples “are actually having children born to them.”

Romney backed up his rhetoric with money, donating $10,000 from his political action committee to a 2006 campaign to outlaw same-sex marriage in South Carolina. The same year, he directed tens of thousands of dollars from his personal family foundation to several conservative groups, including $10,000 to the Massachusetts Family Institute. Mineau said the funds helped defray the $500,000 the group spent on its petition drive for the constitutional amendment.

Romney did not return to his campaign promises of expanding protections for gays and lesbians.

“He didn’t care about his constituents and their rights,” said Julie Goodridge, one of the lead plaintiffs in the original court case, who sued after her partner was barred from her hospital room while she underwent emergency surgery. “He cared about his future as a presidential candidate.”

matea.gold@latimes.com

melanie.mason@latimes.com