He’s getting to write his wrong.

A Brooklyn gangbanger got busted with a loaded, stolen revolver in a caught-on-video incident — but a softie judge cut him loose with little more than a homework assignment, The Post has learned.

Judge Ellen Edwards rejected a prosecution request to set bail at $25,000 for Ismail Abraham, 18, following his arrest in East New York, law-enforcement sources said on Friday.

Instead, Edwards gave Abraham an 8 p.m. curfew and told him to compose a “report on gun violence in the community,” sources said.

It was unclear how many pages Abraham has to write, or when his assignment is due.

Abraham is a member of the “G Stone Crips” and has four prior arrests that are sealed, including two for gun possession during the past year, sources said.

“It just goes to show you how out of touch these judges are,” said a retired NYPD detective who formerly worked in the high-crime neighborhood.

“She should have to sit in jail until he finishes the report. She probably won’t have to make plans for a long time.”

Abraham was arrested around 4:20 p.m. Tuesday when cops saw him toss a .38-caliber Smith & Wesson revolver loaded with five bullets to the ground outside a Newport Street house, court papers say.

Surveillance video also shows him ditching the gun — which was reported stolen in Chicago — while trying to run away down an alley, sources said.

Edwards put the teen back on the street at his arraignment on Wednesday, sources said.

The move came a day after she overruled a prosecution request for $100,000 bail in the case of a teacher charged with repeatedly molesting an 11-year-old girl in his class, including on a school bus during a field trip.

Edwards instead set bail for PS 224 teacher Daniel Santiago at just $7,500.

Edwards, a Democrat, was elected in 2017, when she came in fifth among the candidates for six seats in Brooklyn Civil Court. She was assigned to sit in Brooklyn Criminal Court following her victory.

She wasn’t working Friday and didn’t return messages, but court-system spokesman Lucian Chalfen defended the bail ruling as “well within her discretion.”

Abraham’s Legal Aid lawyer also didn’t return a phone message, and his mother, Nicole Abraham, refused to comment.

“Who told you about my son?” she said before slamming shut the door to her family’s Crown Heights apartment.