A New Jersey appeals court on Wednesday reversed a rape conviction because testimony about whether the defendant had an unusually large penis exceeded its proper scope.

The panel in State v. Pena held that the prejudicial impact of testimony about the defendant’s earlier conviction for exposing himself in public, despite the trial judge’s limiting instruction, substantially outweighed its probative value because the offenses were so similar the jury could have inferred a predisposition to such conduct.

The victim, E.D., told police that outside a bagel store in Butler on Jan. 28, 2007, a man pushed his way into her car, forced her to touch his genitals, then pulled her out, climbed on top of her and jammed his fingers inside her.

E.D., then 19, picked out Andrew Pena from a photo array, and there was other evidence tying him to the assault.

He looked like the man she described to police, he had similar clothing and shoes that matched impressions in the snow at the scene, he possessed a silver Dodge pickup truck that fit her description of the attacker’s vehicle and his license plate was consistent with her partial recollection of the number.

E.D. also claimed she could identify him based on his abnormally big penis.

Pena admitted he was outside the bagel store that night and asked E.D. to move her car because it was in the way, something E.D. said her attacker had done.

But he denied he was the assailant and offered up photographs of his four-inch penis as proof.

The pictures had been taken by a defense investigator while Pena was in jail. During trial, Pena’s wife confirmed they were of her husband.

Morris County Superior Court Judge Salem Ahto initially ruled that the images should be excluded, but he was summarily reversed on a prior, interlocutory appeal.

The Appellate Division held that Pena could introduce the photos but also said the state could seek to establish that the circumstances under which they were taken differed from those at the time of the alleged assault, when the victim described the penis as erect.

When trial resumed, Ahto admitted the photos.

Over a defense objection, he also allowed testimony about a 2002 incident in which Pena pleaded guilty to lewdness for exposing himself to a 20-year-old student, R.K.

Before the prosecutor questioned Pena about it, Ahto told the jury it could consider the testimony “for the sole and limited purpose of whether someone else had the opportunity to observe defendant’s penis and its size under certain circumstances.”

Under questioning, Pena admitted to the R.K. incident and to details resembling those in E.D.’s case. It occurred in a parking lot outside a store, the victim was in a car and Pena, who was masturbating, spoke to her draw her attention.

R.K., at that point employed as an investigator in the special victims’ unit of a county prosecutor’s office, testified that Pena, who was sitting in a parked car next to hers said, “You are so beautiful,” and when she looked at him, she saw he was masturbating.

She described his penis as about eight inches long.

During his closing statement, Assistant Morris County Prosecutor Robert Lane told the jury that the testimony of E.D. and R.K. showed that Pena’s penis “in other circumstances…is bigger than he wants you to believe.”

Ahto’s final instructions to the jurors said they could consider R.K.’s testimony for the sole purpose of whether someone else had the opportunity to observe Pena’s penis “under the certain circumstances that were testified to.”

Pena was convicted on all five charges: first-degree aggravated sexual assault, second-degree burglary and sexual assault, third-degree criminal restraint and fourth-degree sexual contact. Ahto sentenced him to almost 28 years in prison.

Appellate Division Judges Joseph Yannotti, Jerome St. John and George Leone found that Ahto failed to make the findings needed to justify admission of other-crimes evidence.

They reversed for a new trial on four counts but tossed out the charge of criminal restraint by involuntary servitude because it requires forced labor or service that was not present in the case.

Acting Morris County Prosecutor Fredric Knapp said in a statement his office would decide on any next step once it reviews the ruling.

He added that its position is that the evidence “will again support a conviction and we are fully committed to retrying the case if necessary.”

Assistant Deputy Public Defender Jay Wilensky, who handled Pena’s appeal, did not return a call.

Pena’s trial counsel, Alexander Pagano, now a Morris Plains solo, declines comment.