It is an unsettling coincidence that mass shootings bookended the 2018 election, from a Pittsburgh synagogue on Oct. 27 to a bar in Thousand Oaks, Calif., on Nov. 7. The election that took place in between, though, demonstrated that Democrats and even some Republicans found gun-safety advocacy a boon to their campaigns in a way not seen in a long time. In comparison with previous elections, the gun-rights forces’ customary blaring megaphone seemed nowhere near as loud as usual — or as effective. This is borne out by an examination of public attitudes, candidate positions, money and exposure.

Consider first the public environment. According to Pew Research Center analysis, more Americans now favor gun regulation (52 percent) over gun rights (44 percent), a reversal from 2016. And 57 percent say gun laws should be stricter, compared with 52 percent in 2017. A recent Kaiser Foundation poll found gun policy to be the third most important concern of voters, behind health care and the economy. Similarly, Election Day exit polling found the same rank order, except that gun policy was bumped to fourth by immigration — a position it probably would not have lost but for President Trump’s strenuous efforts to exploit immigration anxiety. An NBC News exit poll reported that 60 percent of voters favored stronger gun laws, including 42 percent of gun owners.

Candidates embraced the gun-safety agenda this cycle to a degree not seen since at least the 2000 elections, when Al Gore, the Democratic presidential candidate, made it key to his campaign messaging. According to Mark Kelly, who founded the gun-safety organization Americans for Responsible Solutions with his wife, the former House member Gabrielle Giffords, only four of 36 candidates listed on the Democratic Party’s “red to blue” list in 2016 included the gun issue in their platforms. (The “red to blue” list refers to Republican-held seats Democrats hope to gain.) This year, 38 of 59 candidates on the list included the issue. Candidates for Congress and other offices around the country aggressively touted their support for stronger gun measures, in races in Colorado, Connecticut, Florida, Georgia, Nevada, Pennsylvania, Virginia and elsewhere. Consider it no coincidence that many of these states suffered recent mass shootings.

Members of Congress, including ambitious ones like Tim Ryan, the Ohio Democrat who ran against Nancy Pelosi to be party leader in 2016, and Brian Mast, a Florida Republican, both had A ratings from the National Rifle Association. But both reversed course, trading their A for an N.R.A. F after recent mass shootings. In Pennsylvania’s First Congressional District, representing Bucks and Montgomery Counties, both the Democratic and Republican candidates for Congress advertised their support for stronger gun laws, leading gun-safety forces to split their endorsements between the two (Brian Fitzpatrick, the incumbent Republican, won narrowly).