Estimates based on an analysis of federal background checks by The New York Times.

More guns were sold in December than almost any other month in nearly two decades, continuing a pattern of spikes in sales after terrorist attacks and calls for stricter gun-buying laws, according to federal data released in January.

The heaviest sales last month, driven primarily by handgun sales, followed a call from President Obama to make it harder to buy assault weapons after the terrorist attack in San Bernardino, Calif.

Fear of gun-buying restrictions has been the main driver of spikes in gun sales, far surpassing the effects of mass shootings and terrorist attacks alone, according to an analysis of federal background check data by The New York Times.

During the previous record month, December 2012, Mr. Obama called for new buying restrictions after the mass shooting at Sandy Hook Elementary School.

“President Obama has actually been the best salesman for firearms,” Brian W. Ruttenbur, an analyst with BB&T Capital Markets, a financial services firm, said last month.

These estimates, based on data first reported in 1998, undercount total sales, because some sales are not recorded in states that do not require background checks for private sales.

Gun Control Proposals

Gun sales rose in New Jersey in 2013 after Gov. Chris Christie proposed measures that included expanding background checks and banning certain rifles. (Mr. Christie later vetoed one of the most stringent parts of the proposals.)

The dynamic shows a Catch-22 for gun control proponents: Pushing for new restrictions can lead to an influx of new guns.

When Maryland approved one of the nation’s strictest gun-control measures in May 2013, gun sales jumped as buyers tried to beat the October deadline specified in the measure, which banned most semiautomatic rifles.

As police officers evacuated people from New Orleans after Hurricane Katrina, legally registered guns were confiscated from civilians.

The confiscations outraged gun owners and prompted an increase in gun sales in the area. Conservatives responded by pushing for a federal law prohibiting the seizure of firearms from civilians during an emergency, and many states followed with similar legislation.

A National Increase

Gun sales have more than doubled in a decade, to about 15 million in 2013 from about seven million in 2002. More firearms are sold to residents in the United States than in any other country, according to Jurgen Brauer, a professor at Georgia Regents University.

These exclude permits that allow people in some states to buy multiple guns with a single background check.

The increase is mostly due to higher sales of handguns, which are typically bought for self-defense. Two of the fastest-growing segments of the market are women and gun owners with concealed carry permits.

Looser Restrictions

Legal changes at the local level can lead to abrupt changes in sales.

When Missouri repealed a requirement that gun buyers obtain a permit to buy a handgun in 2007, estimated gun sales went up and stayed up, by roughly 9,000 additional guns per month. The influx shifted gun-trafficking patterns, increasing the number of guns bought in Missouri that were later traced to crimes.

And when the Supreme Court invalidated a ban on handguns in Washington, estimated handguns registered in the city went from near-zero to about 40 every month.