NYPD officers spent hours searching for a cop-hating ex-convict in the Bronx Tuesday night before he fatally shot one of their own, but the gunman eluded pursuers by ducking into doorways whenever a police cruiser passed, officials said Thursday.

A 911 call from Alexander Bonds’ girlfriend about his erratic behavior — less than three hours before he gunned down Officer Miosotis Familia, 48, early Wednesday — sent officers on a futile search for the Bronx man.

Details of the NYPD’s hunt for Bonds, 34, came as police said Thursday he had sought psychiatric treatment at St. Barnabas Hospital in the Bronx days before the shooting and was soon discharged.

In a statement Thursday night, Gov. Andrew M. Cuomo said he had ordered an investigation into why the hospital discharged Bonds so quickly.

“Under tragic circumstances such as these, it is critical to ensure all proper procedures and safeguards were taken,” Cuomo said. “At my direction, the state Department of Health and Office of Mental Health are launching an immediate review of St. Barnabas Hospital’s actions and policies in admitting, treating and discharging this individual. This review will determine if all relevant state laws, regulations and guidelines were followed.”

Police also said a search of Bonds’ apartment turned up antipsychotic drugs as well as antidepressants. A law enforcement source said Thursday that Bonds had kept up with the provisions of his 2013 parole from Attica where he did time for armed robbery.

advertisement | advertise on newsday

Relatives — echoing his girlfriend’s concerns — said Bonds recently appeared to be schizophrenic, NYPD Chief of Detectives Robert Boyce told reporters Thursday after a swearing-in ceremony for new officers at the police academy in College Point, Queens.

Although Bonds’ girlfriend told authorities about his behavior, she assured the 911 operator who took the Fourth of July call that he was not armed or dangerous, Boyce said.

Officers soon began combing Bonds’ Bronx neighborhood for any sign of him and checked a park where they suspected he might have been, Boyce said.

“Each time they would pass by,” Boyce said of officers’ search for the parolee, “Mr. Bonds would duck out of sight.”

The 911 operator who spoke with Bonds’ girlfriend — whom police are not identifying — coordinated the initial police canvas for Bonds Tuesday night, Boyce said.

With his girlfriend following, Bonds walked on Westchester Avenue, blocks from where he shot Familia at 183rd Street and Morris Avenue in Fordham Heights, Boyce said. About 10:30 p.m., according to Boyce, police called off the search for Bonds, although sector cars did keep a lookout.

Boyce said that detectives relied on the girlfriend’s account, which he said was credible, in describing Bonds’ movements to avoid capture in the hours before the shooting.

About 12:30 a.m. Wednesday, Bonds approached Familia — who was wearing her department uniform — as she sat in the passenger seat of the command vehicle, police said.

advertisement | advertise on newsday

The vehicle was parked in the area in an effort to stem recent gang activity, police said after the shooting. Boyce said Bonds apparently fired two rounds from the stolen handgun.

One shot hit Familia in the face, Boyce said, fatally wounding the mother of three and a resident of the Kingsbridge section of the Bronx. Bonds fired the second bullet at cops, according to witnesses, as officers confronted him over Familia’s killing.

When Bonds drew his handgun, officers opened fire, killing him, police said.

Investigators searching Bonds’ apartment found the prescription drugs as well as a muscle relaxant, Boyce said. It remained unclear whether Bonds was taking the drugs, Boyce said.

Also found in the apartment were several mobile telephones, Boyce said, and the devices were being analyzed to determine Bonds’ call activity. He said Bonds posted anti-cop rants on social media.

advertisement | advertise on newsday

On July 1, Bonds visited the Bronx hospital — where Familia died and the NYPD held a news conference early Wednesday to announce the grim news — for a psychiatric treatment, Boyce said. The hospital discharged Bonds the same day, the chief of detectives said.

As a parolee, Bonds was last visited at his home by parole officers on June 15. A law enforcement official who didn’t want to be identified said that Bonds was in compliance with his community supervision-monitoring plan. He had reported to all of his scheduled meetings with his parole officer since his release in May of 2013.

Parole officers conducted random checks of Bonds at his residence and his last visit with a parole officer was June 20, the officials said. His next visit was scheduled for July 11, according to the official.

A wake for Familia was tentatively set for Monday at the Schuyler Hill Funeral Home at 3535 E. Tremont Ave. in the Bronx. Plans for a funeral Mass were pending, officials said.

In Bonds’ neighborhood Thursday, residents said he kept to himself and said they didn’t know him.

At Familia’s home, police officers were stationed outside her door, ushering grieving loved ones in and out as other visitors dropped off food, water and even flowers.

Police Commissioner James O’Neill advised the 524 new cops at Thursday’s academy ceremony not to waver over their new career path, despite another reminder of the dangers that may await them on the street.

“Perhaps a few of your families are questioning whether you made the right decision today, especially after yesterday’s tragedy in the Bronx,” O’Neill told the recruits. “I am here to tell you, you made the right decision.”