WASHINGTON — The suspect in the killing of 12 people at the Washington Navy Yard on Monday test-fired an AR-15 assault rifle at a Virginia gun store last week but was stopped from buying one because state law there limits the sale of such weapons to out-of-state buyers, according to two senior law enforcement officials.

Instead, the suspect, Aaron Alexis of Texas, bought a law-enforcement-style shotgun — an 870 Remington pump-action — and used it on Monday as he rampaged through the navy yard, said the officials, who requested anonymity because the investigation was continuing.

“The gun was broken in half, and he had it in a bag,” one official said of the Remington. “He went inside the building and assembled it in a bathroom.”

The gunman then perched himself above an atrium where he fired down on people who had been eating breakfast, officials said, adding that he used shotgun shells that had roughly a dozen large ball-bearing-like shots in them, increasing their lethal nature.