A jilted ex-boyfriend charged in a double murder spent 3-and-a-half hours inside a New Jersey home before he was caught chasing his lover down the street and stabbing her to death, prosecutors said Wednesday.

Joseph Porter made his first appearance in Essex County Superior Court in Newark, where prosecutors provided a better timeline for how the grisly Aug. 3 slayings in Maplewood went down.

“Videos provided have the defendant entering the residence of the male victim at 2:45 [a.m.] and have him chasing the female victim at 6:15 a.m.,” prosecutor Jason Alterbaum told Judge Nancy Sivilli in requesting that Porter be detained. “Within a span of four hours, this defendant killed two people.”

Porter, 27, of Elizabeth, NJ, allegedly snapped after his gal pal, Karen Bermudez-Rodriguez — an au pair for Manhattan comedy club boss David Kimowitz — broke up with him.

He showed up at Kimowitz’s home in the bucolic neighborhood and used a key the family didn’t know he had to get in.

Once inside, Porter crept up to a second-floor bedroom with a knife and stabbed Kimowitz to death.

Prosecutors did not disclose what time Kimowitz was killed. But they know that “within hours” he gave chase to his 26-year-old ex, who fled the home, and used a different knife to stab her on the street.

The murders happened after Porter and Bermudez-Rodriguez exchanged text messages early that morning in which she demanded back her keys to the Kimowitzes’ home, court papers said.

Kimowitz’s wife and two little girls were away for the weekend at the time.

Porter, who has no prior criminal history, showed no emotion in court as he pleaded not guilty to charges through a Portuguese translator.

Sivilli ordered him detained, saying he’s a flight risk because he tried to escape to Cancun the day of the slayings.

Sources previously told The Post that Porter’s mother had given him $800 for the plane ticket, although it’s unclear whether she knew he was trying to flee.

Additional reporting by Craig McCarthy