There is a reason homeowners can rarely afford to dispense mercy on an overnight invader: Criminal intruders tend to be the dangerous type. What homeowners don’t expect are law enforcers and prosecutors going after them for ­defending themselves and their loved ones.

Queens resident Joel Christopher Paul faced a home-intruder threat in the early hours of July 30, 2017. The 27-year-old was home in Springfield Gardens with his mother, brother and sister when someone ­attempted to break in. The intruder was Shamel Shauvo, 26, who had traveled north from Maryland after being named a suspect in a shooting there 10 days earlier.

Expecting a pizza delivery, Paul’s brother, Michael, 16, went to the door and discovered Shauvo trying to break in. Michael forced Shauvo to the surrounding area, and his mother called for help. Joel, adrenaline likely surging through his veins, answered the call — and brought a bat and knife to the confrontation.

By the time it was all over, Shauvo ­received the ultimate lesson in picking the wrong house. He died at Jamaica Hospital after being clubbed and stabbed. The confrontation had all the indications of a break-in gone wrong for the wanted man, and as one high-ranking police source told The Post, the response was justifiable.

Both brothers avoided arrest and remained home after the incident. But months later, Queens DA Richard Brown submitted the case to a grand jury, bringing ruin upon Joel, who has been charged with manslaughter.

A ham sandwich, as the saying goes, can be indicted in grand-jury proceedings completely overseen by prosecutors. But prosecutors shouldn’t have targeted Joel. The stress, ­expense and uncertainty of facing a first-degree manslaughter charge are devastating and can lead to an unjustified plea that could result in Joel going to prison.

Part of the trouble lies with New York’s “retreat doctrine.” A theory fit for law school classrooms, the doctrine holds Joel had a duty to run and hide if it was safe to do so. It’s an obligation Joel, like the vast majority of New Yorkers, had probably never heard of.

Yet it’s likely that the Queens DA will pursue precisely this avenue at trial, since the indictment states that Joel, “with intent to cause serious physical injury to Shamel Shavuo,” caused his death.

While most jurisdictions would have left Joel alone, the Queens DA seems to want to resurrect the city’s bad old days, when prosecutors developed a reputation of ­interpreting laws in ways that protected criminals more than they protected victims.

There is also an abuse of prosecutorial discretion here. The DA should have recognized that Joel was forced to make split-second ­decisions involving defending his vulnerable family members. Even if Shauvo was initially repelled, Joel had no time for a thoughtful ­inquiry into what Shauvo would do next unless he saw Shavuo’s backside running down the block.

Brown’s office should also ­review its own files to get a better sense of the devastation wrought by home invaders over the years. Such a search will reveal unsolved murders, sexual assaults and general terror inflicted on mostly working-class victims.

For a lesson in the threat posed by home invaders, the Queens DA might also recall the notorious 2007 Cheshire, Conn., home-invasion that ended with the murder and sexual assaults of a mother and her two daughters, one of them just 11 years old.

Other home invaders in this country have had remarkable runs, like the Golden State Killer, who allegedly committed numerous ­assaults in the 1970s. Closer to home, a woman in her 20s last week came home to her apartment from a Manhattan bar only to wake up to the nightmare of an unknown man, who tied her up and raped her.

And what if Joel had acted less assertively and Shauvo had grievously injured Joel’s kin or killed one or more of them? Prosecution after the fact would have ­offered no relief. No criminal sentence can put victims back together. Prosecution doesn’t raise the dead nor mend physical and mental ­scars left by crime.

At times, the only defense is an unrelenting offense against a criminal you can ­assume has the worst of intentions. Unless there is more to this case than the DA has let on, those who neutralize criminals who threaten the sanctity of our homes shouldn’t face criminal charges.

Sean Strockyj is a writer in New York.