A Brooklyn judge freed a man without bail following his arrest in a shooting that sparked a reprisal, which ended up wounding three innocent bystanders, The Post has learned.

Criminal Court Judge Marguerite Dougherty, appointed by Mayor de Blasio in 2016, released Roberto Rivera after his arraignment — even though prosecutors wanted him held on $100,000 bail, sources familiar with the case said.

Rivera, 26, had allegedly fired two rounds at a vehicle after a conversation with a man and a woman inside it on Jan. 2 in Sunset Park.

One of the bullets struck the woman, who was dropped off at Maimonides Hospital, sources said.

A short time later, an unidentified man went to the scene of the shooting at 62nd Street near Third Avenue and opened fire, wounding three men who had nothing to do with the incident, sources said.

The gunfire is believed to have been a botched attempt at retaliation, sources said.

A law-enforcement source familiar with the investigation expressed outrage that Rivera was cut loose after surrendering to cops Jan. 7. The suspect is charged with attempted murder, attempted assault and two counts of criminal possession of a weapon.

“If he doesn’t deserve bail, who does? It is an outrage to let him walk out of court,” the source said.

Rivera was one of three defendants charged with violent felonies whom Dougherty released without bail last Wednesday.

Another is US Army soldier Harold Beard, 28, accused of firing at least 29 rounds from an assault-style rifle out a window of his Dyker Heights home amid a fight with his wife Jan. 7. Beard was released to the custody of the Army.

A court spokesman defended Dougherty releasing Rivera, saying, “If you could abscond and you show up to court knowing the charg­es against you, it would bode well for your returning.”

The third man freed was Omar Nisimov, 31, who allegedly went on the lam for a few days after slashing a victim in Sheepshead Bay. Prosecutors wanted $50,000 bond.