The Hofstra University student killed during a home-invasion robbery was the victim of friendly fire from a veteran cop, Nassau County police revealed last night.

The officer unleashed a barrage of bullets when intruder Dalton Smith pointed a gun at him while using Andrea Rebello as a human shield, police said.

“He kept saying, ‘I’m going to kill her,’ then pointed the gun at the police officer,” Det. Lt. John Azzata said.

The cop fired eight times, with one bullet accidentally hitting Rebello, 21, in the head, he said.

The other seven rounds struck and killed Smith, a career criminal, ex-con and parole absconder, Azzata said.

Smith — clad in dark clothes and a ski mask — was wielding a 9mm pistol with one bullet in the chamber and another in the magazine, Azzata said. But he never got off a shot during the deadly encounter early Friday inside the off-campus house in Uniondale where Rebello lived with her twin sister, Jessica, Azzata said.

The cop who fired the shots was described only as a 12-plus-year veteran of the Nassau County Police Department who earlier served more than seven years with the NYPD.

A source told The Post his decorations include the medal of honor.

He was treated for trauma after the incident, said James Carver, head of the Nassau County Patrolmen’s Benevolent Association.

Nassau County Police Commissioner Thomas Dale said the cop was “OK,” adding: “I believe he’s out sick.”

“We’re going to make sure he receives counseling and appropriate medical attention if he needs it,” Dale said.

Dale also said his department would conduct a “complete investigation.”