A rape victim and her husband turned the tables on her attacker this week in the Bronx — tracking him down to a nearby deli and detaining him until cops came to arrest him, police sources said Saturday.

The victim was walking into a building on Wythe Place near East 170th Street in Mount Eden at around 2 a.m. Friday when a 17-year-old male approached, placed a knife against her neck, forced her under a staircase and demanded that she take her off her pants before raping her, cops said.

The teen also demanded cash and swiped $18 from inside her sock, police sources said.

Then he bolted into the Five Star Deli just around the corner, according to the sources.

The victim, who watched her attacker take off, ran home to tell her husband — and the couple rushed over to the deli, where they stopped him from leaving, the sources said.

Arriving cops arrested the suspect on scene. He was charged with rape, robbery and criminal possession of a weapon, police said.

The woman was taken to Lincoln Medical Center for treatment.

The deli had surveillance video of the ordeal, a worker said, but could not immediately provide it to The Post. Surveillance from a barbershop next door shows cops taking a suspect into custody.

But a clerk at the Bronx District Attorney’s office said late Saturday that their office has so far declined to prosecute the case, but it was not immediately clear why.

The teen suspect was released Friday at 8:20 p.m., according to the clerk.

The 44th Precinct, which covers the area where the alleged rape occurred, logged 44 rapes in 2018, records show. This incident marked the precinct’s first reported rape in 2019.