COLUMBIA, S.C. — Dylann Roof, the man accused of killing nine people this month in a shooting rampage at a storied church in Charleston, S.C., was questioned by an officer earlier this year while hanging around a park, according to a police record released Friday. The officer found parts for a semiautomatic rifle in the trunk of Mr. Roof’s car.

Mr. Roof, 21, was arrested and charged last week in the massacre at Emanuel African Methodist Episcopal Church in Charleston, where on June 17 a white man sat in a Bible study class for about an hour before pulling out a gun and killing nine worshipers, all African-American.

Mr. Roof had at least two previous encounters with the police this year, including one in February when he was charged with possessing Suboxone, a drug used to treat opiate addiction and frequently sold illegally on the street. The arrest came after employees at a Columbia shopping mall reported that he had been asking suspicious questions.