Peter Gotti allegedly bragged he was the “official” boss of the Gambinos more than a year before his brother John Gotti died of cancer, but jurors in his racketeering trial will never hear about it.

Brooklyn federal Judge Frederic Block yesterday tossed out testimony from Michael D’Urso, a former Genovese associate who recorded evidence against his fellow mobsters for three years, in a ruling that left prosecutors reeling.

Block heard a preview of D’Urso’s testimony in an impromptu hearing after he had dismissed the jury.

D’Urso testified that Gotti made his boast in 2000 to Genovese wiseguy Frank DeMeo, who’d just been “made” as a mob member and wanted a formal introduction to the Gambino leader.

So a Genovese capo set up the meeting and presented Gotti as “acting boss.”

“[DeMeo] was taken aback when Peter Gotti said, ‘I’m not acting. I’m official. I run this family,’ ” said D’Urso.

Peter allegedly succeeded John “Dapper Don” Gotti, who died in prison last year. Gotti, who is on trial with six others, is accused of laundering money from the family’s various alleged schemes, including one targeting the city’s waterfront.

Prosecutors were relying on D’Urso, a court-savvy witness who has helped the feds bust more than 60 alleged mobsters, to finger Peter as the Gambino don.

But the judge quickly discounted D’Urso on the grounds that he was not directly involved in the crimes before the court.

He refused to reconsider even after Assistant U.S. Attorney Andrew Genser pointed out that D’Urso was part of a wider waterfront conspiracy that the Genovese and Gambino families allegedly carried out together.

But Block cut prosecutors a break by rescinding a ruling he made Wednesday that would have barred an FBI agent from identifying alleged wiseguys in surveillance photos by crime family and rank.