Dylann Roof bought the semiautomatic handgun he used in last week's church shooting at a gun store 25 miles from his home, according to officials familiar with the sale.
Law enforcement officials say the transaction was entirely legal, despite a pending drug charge.
The officials say Roof bought a 45-caliber Glock handgun on April 11, eight days after he turned 21, at Shooter's Choice in West Columbia, South Carolina.
"We do not give out customer information," said a man who identified himself as the gun store manager but declined to reveal his name.
Roof's friends have told NBC News he used money given to him by his parents as a birthday present.
Roof had been arrested in late February at a Columbia shopping mall and charged with possessing Suboxone, a controlled substance commonly used to treat heroin addiction. He was indicted by a Lexington County grand jury on a state drug charge, a case that is currently pending.
Federal law prohibits the sale of a gun to anyone who is "under indictment for" a felony, but the drug charge Roof faces is a misdemeanor under South Carolina law. For that reason, according to several current and former law enforcement officials, the pending charge did not disqualify Roof from buying a gun.
A separate provision of federal law prohibits the sale of a gun to anyone who is "an unlawful user" of any controlled substance. A provision of the Code of Federal Regulations, which defines that term in the gun law, says habitual use can be inferred from evidence of recent use, examples of which, it says, include "a conviction for use or possession of a controlled substance within the past year," or "multiple arrests for such offenses within the past 5 years."
Current and former ATF officials say a single misdemeanor arrest for possession of a controlled substance would not be disqualifying. The federal courts, these officials say, have tended to be strict in interpreting "unlawful user," and as a consequence, this provision is not often enforced.
For all these reasons, law enforcement officials say, the sale of the gun to Dylann Roof was legal.