A Brooklyn man who beat charges that he tried to kill four members of the Shomrim neighborhood patrol was slapped Friday with a 12-year prison sentence for gun possession.

David Flores, 37, fired shots at the Hasidic men in 2010 when they surrounded his car and beat him because they thought he was masturbating in their Borough Park neighborhood.

He was convicted of only the gun charge in November and hit with the stiff prison sentence as his mother broke down crying.

“That’s not fair! That’s too much! Please don’t do this to me!” wailed Elia Miranda, who collapsed into court officers’ arms and was taken from the Brooklyn Supreme Court chamber.

Flores was acquitted by a jury on 15 other counts, including ­attempted murder, assault and public lewdness.

Prior to his sentencing, an emotional Flores said his life had become an “unbearable nightmare.”

“My life has been completely shattered due to this horrible incident,” he said through tears.

“Not only was I beaten to near death in an unprovoked gang assault, but I have been defamed in the most despicable manner possible which, in itself, carries a lifetime of unjust suspicion and unwarranted scorn against my character.”

The Pennsylvania man also claimed to have been beaten by prison guards and starved while serving jail time because his meals “almost always contained human feces and urine.”

“The toll this treatment takes on the human psyche is sheer misery,” he said.

But Supreme Court Justice Dineen Riviezzo had little sympathy for the career criminal, who told her he “found” the gun he used inside an apartment he was renting in 2001.