WASHINGTON — Survivors and family members of victims of the July 2015 mass shooting at Mother Emanuel AME Church in Charleston, South Carolina, can sue the federal government over failures in the national background check system that allowed the shooter to buy a gun, a federal appeals court ruled Friday.

A lower court judge previously had dismissed the case, finding the government was immune from the claims raised by the Charleston survivors and victims' families. The US Court of Appeals for the 4th Circuit concluded that judge was wrong, and revived the case Friday.

Survivors and family members of victims of mass shootings in the United States have routinely faced obstacles in trying to sue actors they believe are responsible besides the shooter, including state and local agencies involved in vetting gun purchases or responding to shootings, gun makers and dealers, and social media platforms that host hate speech.

The 4th Circuit's decision — which the government could still challenge — reopens one potential avenue for survivors and victims' families to take the federal government to court over its role in running a national background check system meant to stop individuals from getting guns who aren't allowed under state or federal law.

"The families are one step closer to closure," William Wilkins, lead attorney for the survivors and victims' families, told BuzzFeed News on Friday. "What this case said was that the government by law is tasked with developing and implementing and maintaining a system that identifies individuals who by law are not entitled to possess a weapon ... every case is tied to the facts, but this case says that the government is not immune from discharging its responsibilities."

Shortly after the Charleston shooting, in which nine people were killed, then–FBI director James Comey released a statement describing flaws in the federal background check process that made it possible for the shooter, Dylann Roof, to buy a handgun used in the shooting. A jury found Roof guilty on all charges in December 2016 and sentenced him to death; Roof is appealing his conviction before the 4th Circuit.

"Dylann Roof, the alleged killer of so many innocent people at the Emanuel AME church, should not have been allowed to purchase the gun he allegedly used that evening," Comey said at the time, an admission the 4th Circuit noted in the introduction to Friday's opinion.

Under federal law, anyone convicted of a felony or who has illegally used drugs is barred from buying or possessing a firearm. Federally licensed firearm dealers have to run pending gun purchases through the National Instant Criminal Background Check System, or NICS, which is run by the FBI, to make sure the transaction doesn't violate any federal or state laws.

Roof brought a semiautomatic pistol from a federally licensed dealer in West Columbia, South Carolina, in April 2015, a few months before the shooting at Emanuel AME. The dealer did contact the FBI's background check system, and a NICS representative ran a search for information about whether Roof had any disqualifying convictions or drug history.

Roof had been arrested on a drug charge, which wouldn't be disqualifying alone absent a conviction, but the NICS representative also had to check if the arrest records included proof that Roof had used or possessed a controlled substance. Due to the reviewer's confusion about the geography of South Carolina and which law enforcement agency had records about Roof, the NICS representative didn't immediately contact the correct police department, causing a delay.

Firearms dealers are allowed to process gun purchases after a certain period of time even if the NICS review is pending. Because of the delay in Roof's case, the dealer in South Carolina went ahead with the sale. Eventually, the NICS reviewer got a copy of a police report that showed Roof admitted he was in possession of a controlled substance, and the 4th Circuit noted the government didn't dispute that this would have disqualified Roof from legally buying the pistol.

Notwithstanding Comey's admission that the FBI's background check system had failed, a district court judge in South Carolina found that the US government was immune from claims brought by survivors and victims' families under two laws: the Federal Tort Claims Act, which deals generally with claims against the federal government, and the Brady Act, which deals specifically with gun restrictions and who can be held liable after a shooting.

The judge in South Carolina found that under the federal tort law, the government was immune because there was no requirement that NICS reviewers do any follow-up after sending an initial request for information to a law enforcement agency. Under the Brady Act, the judge cited a section that provides immunity against claims related to a failure to stop someone from buying a gun during a background check.

The 4th Circuit concluded that the lower court judge was wrong on both laws. The court noted that a South Carolina sheriff's office explicitly told the reviewer which police department to contact, but she instead looked for other agencies to contact as a result of her geographical confusion about South Carolina. The reviewer was required to contact the arresting agency, the court held — it wasn't a question of whether she was exercising her discretion in following up after an initial request.

"This case turns instead on the NICS Examiner’s alleged negligence in failing to follow a clear directive — contact the arresting agency — contained within the mandatory [Standard Operating Procedures]. The Government can claim no immunity in these circumstances," Chief Judge Roger Gregory wrote in the court's main opinion.

The court also found that the government could be held liable under the Brady Act, because that law only provided immunity to local governments or individual state or federal employees. The federal government itself, which is the entity the survivors and victims' families members sued, is not immune, the court ruled.

"As the Brady Center points out, moreover, when Congress seeks to immunize the Federal Government from liability, it knows how to do so," Gregory wrote, referring to arguments made by the Brady Center to Prevent Gun Violence, a gun control advocacy group.

Jonathan Lowy, chief counsel for the Brady Center, said that the 4th Circuit's decision "reflects an appropriate reluctance of courts to construe laws in a way that exempts bad actors from accountability."

"We think the court correctly understood that the Brady law does not provide immunity to the government or anyone else who subverts the entire purpose of the Brady law, which is to keep guns out of [the hands of] people we all agree shouldn't have them," Lowy said.

The three-judge appeals panel unanimously ruled that the government wasn't immune under the Brady Act. Judge G. Steven Agee split with his two colleagues on the Federal Tort Claims Act issue, writing in a separate opinion that he believed the government was immune from claims under that law.

The Justice Department could petition the full 4th Circuit to reconsider the case, or ask the US Supreme Court to take up the case. A Justice Department representative declined to comment.