WASHINGTON — It was a summer day in 1996 when the Senate held a hearing on a new law that defined marriage as between a man and a woman, shutting out gay couples. The Defense of Marriage Act had overwhelming support, including the backing of President Clinton.

But even then there was a small but vocal objection from Massachusetts.

“It is a mean-spirited form of legislative gay-bashing,” Senator Edward M. Kennedy said at the time, and “flatly unconstitutional.”

That view has gone from being on the political fringes to its very center, swept along in a profound social and cultural transformation on the issue of gay marriage in the United States.

Rarely has such deep change occurred so quickly, culminating in Wednesday’s Supreme Court decision striking down a key part of DOMA. And rarely has one state played as important a role in a nation’s social evolution as Massachusetts has in this one.

In 2003, seven years after Kennedy spoke out, Massachusetts became the first state in the nation to grant same-sex couples the right to marry — a vital moment on the path to Wednesday’s decision.

“It’s incredible to me that, in such a short period of time, we now have federal recognition,” Hillary Goodridge, one of the lead plaintiffs in the Massachusetts gay marriage case, said Wednesday, just after the court ruled. “To have come so far in less than 10 years is astounding.”

Every state in New England has declared same-sex marriage a right, as have six other states and the District of Columbia. Public opinion polls have taken a dramatic turn, from a sizeable majority of Americans opposing gay marriage to a majority now supporting it. President Obama once spoke out against gay marriage, but on Wednesday he tweeted a message from Air Force One: “Love Is Love.”

It’s a change that few could have imagined more than a decade ago, when seven same-sex couples in Massachusetts went to their town halls, applied for marriage licenses and, after being rejected, filed a landmark lawsuit. It was this act of defiance that laid the groundwork, not only for a broader national gay marriage movement but also to repeal the 1996 DOMA law so detested by gay rights advocates.

Providing a test case for gay marriage was, in retrospect, an essential part of a longer-term strategy.

“As long as there was no marriage then the argument that same-sex marriage wasn’t going to cause problems couldn’t be refuted,” said Barney Frank, who was the first openly gay congressman. “It gave us a basis to use some evidence, and show that the notion that this was going to hurt society was totally baseless.”

When Julie and Hillary Goodridge sought their Massachusetts marriage license in March of 2001, the state was, by national standards, well established as socially liberal. A Republican governor, William F. Weld, had expanded rights for gay state workers in the 1990s. The state had repeatedly reelected Frank, who in 1972 filed the first gay rights bill in Massachusetts. Starting in 1998, state lawmakers on Beacon Hill turned back annual attempts to pass a state-based Defense of Marriage Act.

But the Goodridges’ application was immediately denied.

“The law states it has to be a man and a woman,” the clerk said, politely.

But the couple did not stop at that rejection. Two years later, the Goodridges were the lead plaintiffs in the Supreme Judicial Court case that made Massachusetts the first state to recognize same-sex marriages.

That 2003 case helped catalyze a legal, political, and social movement that moved public opinion toward support of gay marriage more quickly than even they and many other advocates anticipated.

“What we didn’t realize, what we never anticipated, was how quickly support would move in our direction,” said Arline Isaacson, cochair of the Massachusetts Gay and Lesbian Political Caucus. “We thought it would happen, but we thought it would take several decades.”

The Goodridge case helped change public attitudes toward same-sex marriage by unleashing a wave of same-sex weddings, where countless aunts, uncles, coworkers, and friends witnessed gay couples pledge to love and support one another.

“Goodridge was one of the building blocks that made it safe for people to declare their sexual orientation without fear they would be ostracized in some way,” said Margaret H. Marshall, the former chief justice of the Supreme Judicial Court who wrote the 2003 decision.

Mary L. Bonauto, lead lawyer in the 2003 SJC case, said that in the first few years after the Goodridge decision, her group was initially reluctant to bring a DOMA challenge to the Supreme Court because gay marriage was still on shaky ground in Massachusetts.

Then-governor Mitt Romney, with his sights on a presidential run, led the opposition against gay marriage. He relied on a 90-year-old law to prevent residents from other states from coming to Massachusetts to marry. He tried to persuade the Legislature to act against same-sex marriage and supported efforts to put a ban on state ballots. “I agree with 3,000 years of recorded history,” Romney said in 2003. “Marriage is an institution between a man and a woman.”

Then, in 2009, Massachusetts became the first state to challenge DOMA, saying it was unconstitutional for the federal government to deny rights to legally married gay couples in Massachusetts. Ultimately, the legal challenge heard by the Supreme Court came from a woman from New York rather than the one filed by Massachusetts.

Even as Massachusetts was expanding rights for same-sex couples, its moves were having the opposite effect in other parts of the country. Opponents began to mobilize, worried that other states might follow Massachusetts.

“We were concerned even back in those days that what happened in Massachusetts would carry over to other states,” said Ron Crews, who led the unsuccessful fight to pass a constitutional amendment to ban gay marriage in Massachusetts nearly a decade ago.

Momentum around the country seemed against gay marriage. Between 1998 and 2012, gay marriage went on 31 state ballots and in all but one case voters effectively prohibited same-sex marriage.

Slowly, that tide shifted. A number of states, either through legislation or court action, followed the lead of Massachusetts. Then, last November, voters in four states — Maine, Washington, Maryland, and Minnesota — endorsed gay marriage. Shortly after the election, a parade of senators began endorsing gay marriage, including a number from conservative states.

Senator Robert J. Portman, the Ohio Republican, disclosed in March that his son was gay, and he was renouncing his opposition to gay marriage. Senator Lisa Murkowsi, Republican of Alaska, said last week she was supporting gay marriage, citing a lesbian military couple from her home state.

As for those who had once supported DOMA, many were relieved on Wednesday that it had been overturned. Bill Clinton, who signed the law as president, has since renounced it.

Richard Socarides, who was Clinton’s principal adviser on gay and lesbian rights issues, celebrated when heard about Wednesday’s decision. “When I saw over the Internet that DOMA was struck down, I thought about all of the misery this law has caused,” he said. “Anybody that had anything to do with it, including myself, is really profoundly sorry. It is a good day that it’s over.”

Gay couples in Massachusetts, and around the country, joined in the celebration on Wednesday as they anticipated the host of changes that will come now that the federal government recognizes their marriages.

Although Massachusetts same-sex couples were recognized by their home state, they were denied more than 1,000 different federal rights. They can now file combined tax returns. Their Social Security and federal health care benefits may be calculated in a more favorable manner. If one of them decides to join the military, they can be treated as spouses.

Or, in the case of one couple from Westminster, Mass., they can now be buried together.

Darrel Hopkins, who has been with his partner, Tom, for 29 years and married since 2004, is an Army chief warrant officer who was awarded two Bronze Stars for his service in the Vietnam War.

In 2008 he had requested for he and Tom to be jointly buried in the state-owned Veterans’ Memorial Cemetery in Winchendon. But not long after their request was approved, the couple were notified that federal officials were threatening to withhold roughly $17 million in veteran cemetery funding if the state approved a same-sex burial where both members were not veterans.

Now, with Wednesday’s decision, they can be buried without any federal complications.