“Defendant’s father told investigators that his son owns a .45-caliber handgun,” the warrant said, the same caliber shell casings that the police had recovered from the church floor.

Mr. Roof, 21, who is white, was charged Friday with nine counts of murder, punishable by death, and one count of criminal possession of a firearm during the commission of a violent crime. Law enforcement officials said that after he was arrested on Thursday in Shelby, N.C., he told investigators he had just done something big in Charleston, and the pistol believed to have been used in the shooting was recovered from his car.

Joseph Meek, a friend of Mr. Roof’s, said that his parents each gave him $350 toward the purchase of the gun, which he bought this spring, and that at some point they took it away from him. There have been reports that his parents gave him the gun directly, as a 21st birthday present, but Mr. Meek said Mr. Roof made a point of buying it himself so that his parents would not be implicated in any trouble he might get into.

Friends said Mr. Roof voiced virulently racist views and had talked recently about starting a new civil war — even about shooting black people. Photographs of him wearing patches with the flags of the former white supremacist governments of South Africa and Rhodesia, and leaning against a car with Confederate States of America on its license plate, drew millions of views online.

Gov. Nikki R. Haley, a Republican, was one of many officials to label the shootings a hate crime, and called for the death penalty in the case.