SAN FRANCISCO — A federal appeals court Tuesday overturned the murder conviction of a man accused of gunning down a 19-year-old student at a Gilroy convenience store, arguing the prosecutor — now a Santa Clara County judge — made inflammatory, racially charged closing remarks that the defense should have objected to.

The decision by the Ninth U.S. Circuit Court of Appeals said the prosecutor, Stuart Scott, gave closing arguments tainted by “falsified, inflammatory and ethnically charged remarks” that incited the jury in 2004 to find Paul Zapata guilty in just three hours despite conflicting witness testimony.

“Scott wove out of whole cloth, with no evidentiary support, a fictional and highly emotional account of the last words (the victim) heard Zapata shout as Zapata supposedly shot him,” the ruling stated, adding that Scott ascribed to Zapata “several despicable, inflammatory ethnic slurs.”

The unanimous, three-judge decision can be appealed to the U.S. Supreme Court, but experts consider it unlikely the justices would take up the matter.

The ruling is the latest embarrassing incident for the judge, who was elected last June after running unopposed for a seat on the Santa Clara County Superior Court bench. In March, Scott got in hot water for violating a basic fairness rule by calling a prosecutor into his chambers after a trial, complimenting her, trashing the defense attorney and saying what his likely sentence would be.

Scott declined to comment. A spokeswoman for the state Attorney General’s Office said the ruling is still under review, pending a decision on whether to appeal it.

The District Attorney’s Office could refile charges but at this point “is studying the court’s decision and will review the case file to determine our next step,” Assistant District Attorney Scott Tsui said.

Zapata was convicted of the May 2001 shooting of 19-year-old student Juan Trigueros in a 7-Eleven parking lot in Gilroy. Trigueros was wearing a basketball jersey with number “8,” for Los Angeles Lakers starter Kobe Bryant. Stuart told jurors the number is associated with a rival gang.

“He died because he was born in Mexico and he made the mistake of wearing a number 8 jersey on Leavesley Avenue,” Scott told the jury.

A witness saw a man who loosely fit Zapata’s description yelling at Trigueros, who was on a pay phone. But he could not hear what was said.

Scott, however, told the jury three times that Zapata shouted derogatory terms for Mexicans and Sureño gang members.

“What a way to leave this world,” Scott told the panel.

The prosecutor at one point told the jury it was a reasonable inference that Zapata uttered those insults because he’d made similar derogatory statements in the course of committing other crimes, including assaults against rivals.

But the appellate court noted that Scott made repeated comments that baldly intimated that those were his actual words.

“By concocting the details of the victim’s dying experience in this manner, the prosecutor purposely blurred the distinction between Zapata’s past convictions and the crime for which he was standing trial,” the appeals court ruled.

The appellate court reversed Zapata’s conviction on the technical grounds that the defense attorney, retired public defender John Vaughn, provided “ineffective assistance of counsel” because he failed to object to Scott’s closing remarks. But the court branded Scott for making “egregious misstatements.” A state appeals court also called the questionable parts of his closing statement “pure fiction,” though it ruled his misconduct was “harmless error.”

However, the federal court concluded that the verdict might have been different if Scott hadn’t concocted the dramatic account of the very last words Trigueros heard. The defense argued the prosecution was unable to link Zapata to the scene of the crime either through positive eyewitness identification or physical evidence, and cited bias and credibility problems with several prosecution witnesses.

“The likelihood the jury’s decision was influenced by the prosecutor’s egregious and inflammatory closing argument is heightened because the evidence against Zapata was weak, and the eyewitness and circumstantial evidence was far from overwhelming,” the federal court found.

The Sixth District Appellate Program, which handled the matter in state court, praised the federal court for its ruling.

“The primary vice in prosecutorial misconduct is that it can lead to the conviction of the innocent,” said Dallas Sacher, the group’s executive director. “In this case, the prosecutor invented facts and played on emotion in order to overcome the evidentiary weaknesses in his case. The Ninth Circuit correctly concluded that these tactics cannot be tolerated when the freedom of a citizen is at stake.”

Contact Tracey Kaplan at 408-278-3482. Follow her at Twitter.com @tkaplanreport.