CHARLESTON, S.C.?About a month ago, Dylann Roof's family became concerned. The once-quiet, bright boy from a middle-class family had been drifting and began to tell relatives he was involved in racist groups.
"He turned into a loner in the last couple of years and no one knew why," said a woman reached at the house of his former stepmother.
On Wednesday evening, police said, the 21-year-old Mr. Roof entered an African-American church here that dates to the time of slavery, sat quietly through an hour or so of Bible study, then pulled out a pistol and methodically killed nine people.
Thursday morning, after a massive manhunt, police in Shelby, N.C., some 240 miles to the northwest, apprehended Mr. Roof after a traffic stop. Authorities had received a tip from a motorist who reported seeing a person in a nearby car who resembled a man in surveillance video from the shooting scene that had been posted online. The car carried a Confederate-flag novelty license plate.
Among those he allegedly gunned down Wednesday night inside Emanuel African Methodist Episcopal Church, one of the nation's most historic African-American houses of worship, was its leader, the Rev. Clementa Pinckney, a long-serving South Carolina state senator and civil rights leader.
The other victims, who ranged in age from 26 to 87, included three other religious leaders at the church. One was a high school track coach, another was an up-and-coming minister and the third was a 74-year-old pastor at Emmanuel.
Mr. Roof told his horrified victims that African-Americans were "raping our women" and purposely left one person alive to share his motivations, according to a person familiar with the investigation.
President Barack Obama said Thursday that "this is not the first time that black churches have been attacked. And we know that hatred across races and faiths pose a particular threat to our democracy and our ideals."
The violence came at a time of heightened racial sensitivity after the shootings of African-American suspects in disputed incidents by police?including one a few miles away in neighboring North Charleston, where a cellphone video in April captured an officer shooting to death an unarmed man, Walter Scott, in the back as he was running away.
Local authorities branded the church shooting a hate crime, and the Federal Bureau of Investigation launched its own parallel investigation, which could ultimately lead to federal prosecution.
Still, Attorney General Loretta Lynch said that while the Justice Department was investigating the case as a hate crime, it was too soon to say whether state or federal authorities would prosecute Mr. Roof on such charges.
Mr. Pinckney, 41, was a married father of two daughters who began serving in the South Carolina Legislature in 1997, making him, at age 23, the youngest member of the state House at the time. He had recently played a key role in helping pass legislation to provide body cameras for all South Carolina police officers in the aftermath of the Walter Scott shooting, lawmakers said.
Bakari Sellers, a former Democratic state representative and friend of Mr. Pinckney, said Mr. Pinckney's family has been informed by authorities that Mr. Roof had been given a pistol for his 21st birthday, and that he was driving a car with a Confederate flag vanity plate.
Mr. Roof had repeated ninth grade in Lexington, S.C., and left school in February 2010, a spokeswoman for Lexington County School District One said. A month later, Mr. Roof enrolled as a ninth-grade student at Dreher High School in Columbia, S.C., according to Richland County School District One. He attended through May of 2010 but didn't return, a district official said.
The woman who said Mr. Roof had begun to express racist views described him as a bright child who stopped applying himself at school. The woman said Mr. Roof's ex-stepmother is her daughter.
Mr. Roof's last known address was in Eastover, S.C., a rural community about 15 miles southeast of Columbia, the state capital. The property has two houses, and people at both declined to comment.
Mr. Roof had lived off and on with his father, Ben Roof, in Columbia, a family friend said. He described the father as a hardworking, friendly, churchgoing man who had recently expressed concerns about his son's lack of direction.
The friend described the suspect as a lanky young man who was a loner who rarely smiled. "You could see that he was troubled," he said.
The elder Mr. Roof has a racially diverse set of friends, and wouldn't have taught his son racial intolerance, the friend said. "There are African-Americans over at that home all the time," the friend said.
The elder Mr. Roof couldn't be reached for comment.
The woman reached at Dylann Roof's ex-stepmother's house added that the young man "just fell off the grid somehow."
Mr. Roof was acting suspiciously in the months before the shooting, according to a police report. On Feb. 28, he was arrested for drug possession at a Columbia mall, where the report said he was wearing all black and rattling employees at two stores with unusual questions about staffing and operating hours.
In the incident report, the arresting officer said Mr. Roof was nervous and said his parents were pressuring him to get a job, though he acknowledged he hadn't asked for an application from the stores.
Mr. Roof was released two days later from the Lexington County Detention Center on a $5,000 personal recognizance bond, said Maj. John Allard, a spokesman for the county sheriff.
The mall's manager and security office didn't respond to requests for comment.
Mr. Roof was banned from the mall for a year but was spotted at the facility and arrested in its parking lot on April 26, when he was charged with trespassing, another police report said. His car was turned over to his mother, and he was placed on a new three-year ban, the police record said.
Mr. Roof was released on $470 bond after the trespassing incident, Maj. Allard said.
Mr. Roof's grandfather, Columbia lawyer C. Joseph Roof, declined to speak at length about his grandson, but said, "I can tell you that I love him."
A photo of Mr. Roof on what appears to be his Facebook page shows him wearing patches representing South Africa's apartheid-era government and the former white-ruled country Rhodesia.
In both police reports Mr. Roof gave his middle name as Storm, which is popular among white supremacists and could derive from stormfront.org, a website frequented by so-called white racialists, according to a person familiar with such groups.
Nathan Koppel and Cameron McWhirter contributed to this article. Lisa Schwartz contributed research.
Corrections & Amplifications
Authorities were able to identify and capture Mr. Roof through tips to law enforcement, police said. An earlier version of this story incorrectly said authorities traced him to North Carolina because he had used his own cellphone to call the Charleston police department with a bomb threat against the church.
Write to Valerie Bauerlein at firstname.lastname@example.org, Cameron McWhirter at email@example.com and Ana Campoy at firstname.lastname@example.org