It’s getting rougher out there for New York’s Finest.

Four NYPD cops were walloped by a child’s Barbie bike that was tossed at them from a fifth-floor balcony in Brooklyn while they were busting a gunman early Sunday, officials said.

The attack raised fears of a new wave of anti-cop violence — with a police union president blaming the assault on Mayor Bill de Blasio and his crackdown on stop-and-frisk.

“The atmosphere is, ‘We’re going to do what we want,’ that ‘We’re going to get away with it,’ ” said Ed Mullins, president of the Sergeants Benevolent Association.

“There’s a perception that the mayor is soft on crime. The perps’ perception is that the cops are backing down.”

One officer suffered a gash to his head that required six staples and a stitch. Three others suffered a concussion, bruising to the head and a cut forearm, respectively.

Bryan Jiminez, 35, was charged with four counts of attempted murder of a police officer in the Crown Heights attack.

The cops had raced to 959 St. Mark’s Ave. at 2:05 a.m. in response to a report of shots fired, law-enforcement sources said.

After nabbing suspected gunman Jeanick McVane, 21, the officers were allegedly set upon by two men — Nicholas John, 20, and Samuel Clark, 21 — who tried to keep McVane from getting hauled off, sources said.

A cop had Tasered one of the alleged interlopers when the pink-and-purple bicycle with training wheels came plummeting at them.

More cops arrived and traced the aerial assault to Apartment 5D, where they arrested Jiminez.

Shirtless and handcuffed, Jiminez was taken from the 77th Precinct house to Kingsbrook Jewish Medical Center for a psych exam.

Also busted was apartment resident Lelia Matos, 49, who was charged with obstruction for allegedly refusing to open the door to police.

One resident said crime in the area was “getting out of control.”

“The cops are scared for their lives,” said Nadja White, 32. “You can’t even bring your kids outside anymore.”

Mullins said last year’s federal court ruling against stop-and-frisk and the City Council’s passage of a law that makes it easier for people to sue cops over alleged racial profiling is hurting the police.

“They’ve made the police the bad guy,” he said.

“I don’t think there’s a parent in America who didn’t tell their kid, ‘If you get lost, go to the police.’ ”

Such assaults on cops, which they call “airmail” attacks, were common during high-crime eras, with one NYPD veteran recalling how officers “would always stand under awnings or fire escapes for cover.”

In 1993, Housing Authority Officer John Williamson was killed by a 30-pound bucket of spackle.

A de Blasio spokesman on Sunday noted, “Crime is down in most categories,” and said 1,200 more officers were being deployed this summer in areas where there have been spikes.

Additional reporting by Frank Rosario and Aaron Short