Marcus Yam for The New York Times

NEWTOWN, Conn. — Six years ago this month, Mark Barden and Nicole Hockley watched from the gallery, counting the yeas, as the Senate voted on expanding background checks.

Four months had passed since his son, Daniel, and her son, Dylan, were killed at Sandy Hook Elementary School, and at no point in that time had they imagined the bill would fail. The assault weapons ban the Senate rejected the same day was one thing, but background checks seemed like “low-hanging fruit,” Ms. Hockley said.

The bill failed.

Afterward, standing by President Barack Obama at a news conference in the Rose Garden, Ms. Hockley focused all her energy on not bursting into tears. Mr. Barden looked at his wife, Jackie, and their two surviving children and thought: “I’ve failed you. Your country has failed you.”

To many people who thought the massacre of 20 first graders and six of their educators would fundamentally change the nation’s gun politics, the loss felt irrecoverable. But those votes in April 2013 turned out to be a beginning, not an end.

They led to new activism and organizations and fresh approaches to the gun control debate, and they helped motivate gun control advocates like Michael R. Bloomberg, who brought more money and visibility to the cause. Those groups, in turn, provided critical resources for the survivors, family members and activists galvanized by the shooting at Marjory Stoneman Douglas High School in Parkland, Fla., in February 2018.

Now, as the National Rifle Association struggles with internal battles, gun issues figure prominently in presidential politics, and mass shootings like Saturday’s assault at a California synagogue continue on a regular basis, the influence of the Sandy Hook activism is a sharp reminder that federal inaction or setbacks on issues like guns are seldom a final word. Instead, progress on gun violence and other social issues is often a long, slow process that builds on failures as well as successes.

“There was logic to the idea that if Sandy Hook didn’t create an epiphany in this country, what will?” said Senator Christopher S. Murphy of Connecticut, one of Congress’s most vocal proponents of stricter gun laws. “But that’s not how politics works. There are almost no epiphany moments in American politics. You have to build your power, and we had none of it.”

The families who fought for the 2013 legislation were stunned by its defeat. But “those of us who have experienced this kind of loss find a resolution or a resolve,” said David Wheeler, whose son Ben was killed at Sandy Hook. “Because what else can they take?”

As public attention faded, the families and organizations that had sprung up around gun issues changed their strategy. What started as a legislative campaign became an effort to build infrastructure for future fights.

The National Rifle Association had spent decades doing exactly that. Long before Sandy Hook, before Columbine, it was working tirelessly to accumulate influence in Washington.

There was some organizing on the other side: The group now called the Brady Campaign to Prevent Gun Violence was instrumental in passing the 1993 Brady Law, which instituted federal background checks, and the 1994 Assault Weapons Ban, which prohibited some semiautomatic weapons. (The ban expired in 2004.) But Brady’s influence was dwarfed by the N.R.A.’s single-issue voters, millions of dollars in political spending and preternatural ability to mobilize.

That power imbalance changed because of Sandy Hook.

The shooting itself instantly spawned new organizations. Within hours, Shannon Watts, a mother of five in Indiana, went looking for a gun-related equivalent to Mothers Against Drunk Driving and found none. So she created a Facebook page, which ballooned into Moms Demand Action.