NEW YORK — A federal jury Thursday found a Brooklyn gang leader guilty of all 21 counts he had been tried for, including three murders, racketeering and drug trafficking, in a case that featured amateur rap videos of him rhyming about carrying guns and settling scores with bullets.

The trial of Ronald Herron, in U.S. District Court in Brooklyn, brought testimony from fellow gang members and former friends; a rap star named Uncle Murda; and a linguistics expert who testified about how rappers used lyrics.

Herron’s mother was a cocaine and heroin user who allowed friends and relatives to package and deal drugs from their apartment, Herron testified. He joined the Bloods when he went to a juvenile-detention facility at 14 after an armed robbery, he said, and when he returned home, became more involved in violence and drug dealing.

In and out of jail and prison since his first stint in the correctional system, Herron, prosecutors said, wielded an enormous amount of power. They said he had risen from a low-level drug dealer to the top of his Bloods “set,” called the Murderous Mad Dawgs.

Save 75% on a Digital Subscription Today

Before trial, the defense had argued Herron’s recordings were constitutionally protected free speech that should be off-limits. But the judge ruled that the recordings could be used as evidence to establish Herron’s identity as the leader of the Murderous Mad Dogs.

Herron testified that he decided to leave his life of crime and pursue a hip-hop career using the name “Ra Diggs” in 2007 after serving a six-year prison term for drug dealing. He described pursuing a rap career using lyrics that drew on his experiences growing up in a drug-plagued housing project in Brooklyn.

The defense said he had become a serious artist while in prison, ultimately putting in long hours in the recording studio and in clubs promoting his career.

Herron, 32, testified that the lyrics from one of his videos seen by the jury — “See if he was smart he would’ve shot me in the head / ‘Cause I can get you shot from a hospital bed” — were a reference to a person who wounded him in a shooting. But he insisted he never took revenge on anyone, calling the lines exaggeration and hyperbole.

The jury asked for copies of testimony from three witnesses, along with a rap video of Herron’s, and surveillance-camera footage from city housing projects before it reached its verdict.

He was convicted of murdering three men associated with drugs: Frederick Brooks, Richard Russo and Victor Zapata.

Loretta Lynch, the U.S. attorney for the Eastern District of New York, said in a statement: “He styled himself a rap artist, but the jury’s verdict makes clear who Herron really is: a drug dealer and murderer who sought power through fear and intimidation.”

The case was the latest battleground in the debate over whether rap lyrics constitute criminal evidence. The American Civil Liberties Union has said that in 18 cases nationwide in which courts considered rap music evidence, they were admitted about 80 percent of the time.

Sentencing was set for Oct. 1.