Federal law barred Jody Lee Hunt from ever owning a gun. But when he wanted to buy one, it wasn’t hard: He found a seller on Facebook.

Mr. Hunt was a felon who had spent time in prison for abducting a girlfriend. But in December 2014, he used the handgun he found online to carry out a rampage in West Virginia, the authorities said, killing his ex-girlfriend, a rival business owner, and two others. In a note he wrote before turning the gun on himself, he said he wanted his victims to get “their fair pay of hurt.”

Millions of people in the United States are prohibited from owning firearms under federal law. They include felons like Mr. Hunt as well as fugitives, people adjudicated to be mentally ill, those dishonorably discharged from the military, and also convicted domestic abusers or others subject to domestic violence restraining orders.

They are supposed to be blocked by a federal instant background check database that licensed firearms dealers are required to query before handing weapons over to a buyer. This system has barred more than three million sales since it was enacted in 1993.