The Hofstra University student killed during a home invasion robbery was the victim of friendly fire from a veteran cop who unleashed a barrage of bullets when the armed intruder pointed a gun at him, Nassau County police announced tonight.

Andrea Rebello was accidentally shot in the head while career criminal Dalton Smith had her in a headlock and used her as a human shield while trying to escape out the back door, Det. Lt. John Azzata said.

The unidentified cop fired eight rounds, seven of which struck and killed Smith, and one of which hit Rebello, he said.

Smith was wielding a 9mm pistol with a bullet in the chamber and another in the magazine, Azzata said.

But he never got off a shot during the deadly violence early Friday morning inside Rebello’s off-campus house in Uniondale, said police.

The cop who got off 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.

Smith was identified by his fingerprints earlier today. He had been wanted since April for absconding from parole. His criminal record includes armed robbery and automobile theft convictions, records show.

Smith stormed the California Avenue home just after 2 a.m., demanding money from the man and three women inside. One of the women called 911 when she was asked to go to an ATM to get more cash, police said.

Cops arrived minutes later, exchanging gunfire with Smith, who was shot dead.

Andrea Rebello, 21, of Tarrytown, was also shot and killed during the incident, which took place just two days before spring commencement.

Rebello, 21, was a stunning social butterfly who plastered party pictures all over social media — but she also had a little-known domestic side in which she cooked, gardened and enjoyed family.

The beloved sorority girl — a junior public- relations major with a sociology minor at Hofstra University — was rarely seen without her twin sister, Jessica, friends and teachers said.

“They were always together — like Velcro,” said a friend, Michelle.

Her former principal at Sleepy Hollow HS called the girls “a set,” adding it was difficult to think of them separately.

“She had a devotion to family and sense of purpose and of opportunity,” said Principal Carol Conklin-Spillane.

Rebello grew up well off in Tarrytown, Westchester, where her father, Fernando, runs a successful landscaping company.

In high school, she made the English honor roll. In her yearbook, which features a photo of her in a dark gown, she quoted Benjamin Franklin and Bob Marley. Next to her photo, it reads, “Love the life you live, live the life you love.”