An 18-year-old man who was targeting members of the lesbian, gay, bisexual and transgender community was charged with first-degree murder in the killings of three people in a Detroit home, the authorities said.

Officials said the man, Devon Robinson, shot the victims — two of whom were gay and one who was a transgender woman — on May 25. An investigation by the Detroit police led to his arrest on Thursday, prosecutors said in a statement.

Officials said Mr. Robinson also shot two other people who survived their injuries. Maria Miller, an assistant prosecutor, said on Saturday that a motive would be revealed at a trial.

“It is alleged that these victims were targeted and killed because they were part of the L.G.B.T.Q. community,” she said.