FBI Director Says Background Check System Failed, Allowing Alleged SC Shooter to Purchase Gun The agency has ordered a 30-day review into the matter.

 -- The FBI says its background-check system failed, mistakenly allowing the man who allegedly opened fire inside a South Carolina church last month to purchase the gun he used in the rampage.

"We are all sick that this has happened," FBI Director James Comey told a small group of reporters in Washington today. "We wish we could turn back time."

Comey said 21-year-old Dylann Roof of Lexington, South Carolina, "should not have been allowed" to buy the weapon that ultimately killed nine people, including the pastor of the historic Emanuel AME church.

Through a database known as the National Instant Criminal Background Check System -- or "NICS" -- the FBI performs background checks for those looking to buy weapons from dealers in 30 states, including South Carolina. If FBI examiners don't respond within three business days, federal law allows the dealers to decide themselves whether to proceed with the sale.

After Roof tried to buy a gun from a dealer outside Columbia on April 11, an FBI examiner found a felony drug charge in his record -- but in follow-up the examiner missed that Roof had actually admitted to possessing the drugs during his March arrest, Comey said. That admission should have barred Roof from buying the gun.

With no word from the FBI examiner, the dealer allowed Roof's purchase to go forward on April 16, according to the FBI director.

"This case rips all our hearts out," Comey insisted today.

He said the FBI examiner missed the key fact in Roof's record due to a complicated layout of police jurisdiction in Columbia.

"Not knowing the geography, she did what she was supposed to do and followed our protocols," Comey said. Nevertheless, he has ordered a 30-day review of the matter.

FBI officials met this morning with family members of the nine people killed in the attack.

Comey's admission comes on the same day history was made in South Carolina, where state officials removed the Confederate flag from state capitol grounds this morning in Columbia.

The flag's removal was prompted by the rampage inside the predominantly black Charleston church -- a tragedy that renewed public debate over the significance of the Confederate flag and race relations in America.

Speaking at a memorial service for Rev. Clementa Pinckney, President Obama said, "For too long, we’ve been blind to the unique mayhem that gun violence inflicts upon this nation. Sporadically, our eyes are open."

Nevertheless, the president warned, "None of us should believe that a handful of gun safety measures will prevent every tragedy. It will not."

Roof had been "planning something like that for six months," Roof’s roommate said after the shooting.

"He was big into segregation and other stuff," according to Dalton Tyler, who said he has known Roof for at least seven months. "He said he wanted to start a civil war. He said he was going to do something like that and then kill himself."

Roof had initially been charged with nine counts of murder and has since been charged with three more counts of murder tied to the surviving victims.

Get real-time updates as this story unfolds. To start, just "star" this story in ABC News' phone app. Download ABC News for iPhone here or ABC News for Android here.