LOS ANGELES — Katy Perry, her collaborators and her record label must pay more than $2.78 million because the pop star’s 2013 hit “Dark Horse” copied a Christian rap song, a jury decided Thursday.

It was an underdog victory for rapper Marcus Gray, a relatively obscure artist once known as Flame whose 5-year-old lawsuit survived constant court challenges and a trial against top-flight attorneys for Perry and the five other music-industry heavyweights who wrote her song.

But the amount was less than the nearly $20 million sought by attorneys for Gray and his two co-writers on the 2009 song “Joyful Noise” but they said they were pleased with the decision.

“These defendants have made millions and millions of dollars from their infringement of the plaintiff’s copyright,” Gray’s attorney, Michael A. Kahn, told the jury.

Perry herself was hit for just over $550,000, with Capitol Records responsible for the vast majority of the money. Defense attorneys had argued for an award of about $360,000 after the jury decided earlier this week that “Dark Horse” copied “Joyful Noise.”

Perry’s attorney, Christine Lepera, said they plan to vigorously fight the decision.

“The writers of Dark Horse consider this a travesty of justice,” Lepera said.

Both sides agree that Perry herself made a profit of $2.4 million, while Gray’s attorneys argued that her song had grossed about $41 million. The pop star testified at the beginning of the trial but has not been in court since.

Because the rhythmic instrumental riff from “Joyful Noise” plays through 45% of “Dark Horse,” Kahn said his clients were entitled to 45% of the entire earnings of Perry’s album “Prism,” where her song appears.

The defense recommended dividing the award money by the number of songs on the album.

“A CD is a CD, you can’t break it into pieces,” Kahn said. “Every album had an infringing song. And not just any song, but the most popular song on the album.”

Both sides agree that sales and streams of “Dark Horse” should be in play.

Lawyers for Perry and her co-defendants, which include Capitol Records and producer Dr. Luke, said the millions Gray sought were based on ludicrous figures.

“They’re not seeking fairness,” the defendants’ attorney, Aaron M. Wais, told the jury. “They’re seeking to obtain as much money as possible.”

Wais argued, based on expert testimony, that the disputed part of “Dark Horse” was worth only 5% of its earnings.

He argued that the biggest driver of the song’s earnings were not any part of the song itself, but the celebrity of Perry, who was already a major star when she recorded the song.

“The reason why people buy a Katy Perry album, buy a Katy Perry song, is because it’s Katy Perry,” Wais told the jurors. “If you replaced her with an anonymous artist, do you really think it would sell as well?”