Four armed officers and years of warnings did nothing to stop Nikolas Cruz from massacring 17 people at a high school.

Not one but four sheriff’s deputies hid behind cars instead of storming Marjory Stoneman Douglas HS in Parkland, Fla., during Wednesday’s school shooting, police claimed Friday — as newly released records revealed the Broward County Sheriff’s Office had received at least 18 calls about the troubled teen over the past decade.

Sources from Coral Springs, Fla., Police Department tell CNN that when its officers arrived on the scene Wednesday, they were shocked to find three Broward County Sheriff’s deputies behind their cars with weapons drawn.

The school’s armed resource officer, Broward County Sheriff’s Deputy Scot Peterson, was also outside. He resigned on Thursday after his failure to act was publicly revealed.

The Coral Springs cops entered the building to engage the shooter on their own, before other Broward County deputies arrived, two of whom joined the police inside, the sources said.

It was unclear whether the shooter was still inside at the time, CNN reported.

Coral Springs City Manager Mike Goodrum confronted Broward County Sheriff Scott Israel during a vigil for victims the next day, saying students could have been dying in the school while the deputies held back.

The next day, Coral Springs Police Chief Tony Pustizzi wrote in an internal e-mail that “another agency has given the impression that it had provided the majority of the rescue efforts.”

“Please know that this issue will be addressed, and the truth will come out in time,” he wrote.

In an official statement Friday, the police department said only that “any actions or inactions that negatively affected the response will be investigated.”

News of the deputies’ apparent inaction came after the sheriff’s office released records showing how many times it had received alarming reports about Cruz, 19, over the years — including two that specifically warned he was a potential school shooter.

The records show that a neighbor called in February 2016 to report that Cruz “planned to shoot up the school” and had posted photos to Instagram of himself posing with guns.

The information was passed on to Peterson, but it was not clear what, if anything, he did with it.

Another person phoned the sheriff’s office in November last year to say the teen was stockpiling guns and knives and warn that “he could be a school shooter in the making,” the records show.

But the caller was told to contact the Palm Beach Sheriff’s Office instead because Cruz had moved out of Broward, according to the records.

In September 2016, a peer counselor told Peterson that Cruz had tried to kill himself by drinking gasoline, was cutting himself, possessed hate symbols and expressed a desire to buy a gun “for hunting.”

This time, Peterson did make a report, but a mental-health worker determined Cruz didn’t meet the state’s criteria for involuntary commitment to a psychiatric facility, the records show.

Cruz stayed at the school for another five months before he was transferred out.

President Trump sharply criticized Peterson on Friday.

“He trained his whole life. When it came time to get in there and do something, he didn’t have the courage or something happened, but he certainly did a poor job — there’s no question about that,” Trump told a reporter.

Video, meanwhile, emerged of Peterson touting the value of resource officers like himself during a 2015 school-board meeting.

“We are crime prevention. An audit report will never show how much we prevent,” he tells the board members, according to the Sun Sentinel.

Peterson also brags of chasing four people through a school with his gun after the cafeteria alarm went off, and recalls responding to a report of an armed man wearing a ski mask

“So I ran, put some shorts on, ran out with my firearm, while I’m running to the school, I’m contacting Coconut Creek police, we set up a perimeter,” he said.

It turned out the miscreant was an 18-year-old senior with a paintball gun.

Additional reporting by Yaron Steinbach