A retired NYPD detective shot two of his sons when they tried to play peacemaker as he argued with relatives over the weekend — and then killed himself, authorities said Monday.

Irvin Noak, 61 — who had a son in the NYPD — was at a backyard barbecue at the family’s home in Bellport, LI, on Sunday when he began fighting with relatives at about 11 p.m., police said.

His sons Aaron, 22, and Irvin Noak III, 30, “intervened during the argument,’’ Suffolk County police said in a statement.

“Noak then retrieved a handgun from his bedroom and shot his two sons. Noak then shot himself.’’

The dad was rushed to Brookhaven Memorial Hospital Medical Center in East Patchogue, where he was pronounced dead.

The sons, who lived at home with their dad on Fox Glove Circle, were taken to the same hospital, where they remain in critical condition, authorities said.

Balloons, lawn chairs and beer bottles were still strewn about the property Monday as cops investigated the incident.

Noak worked for the NYPD from 1982 to 2009, when he retired as a Manhattan North detective, sources said. His NYPD son was not present when Noak started shooting.

A neighbor said she heard shots ring out inside the family’s home, followed by the sound of women screaming.

“It sounded like crying and shouting,” said Stephanie Bilski, 38. “It’s just so sad.”

Another neighbor who knew Irvin Noak for more than a decade called him “one of the nicest guys you could ever meet.’’

“I never even saw the father argue; there was never any clue that anything like this could ever happen,’’ said the neighbor. “They were a beautiful family. Nothing to indicate anything disturbing.”

Dequan Wilson, 17, who knows the family and works for the party company from which Noak rented a tent for the BBQ, said the dad seemed excited about the festivities.

“I set up the tent. . . I saw [Noak], he came out and greeted us,” Wilson said. “He seemed happy — his usual self.

“I told him I was going to stop by later, and he said, ‘I’ll definitely bring you a plate of food.’”

“They’re the ideal family. This is just a nightmare.”

Additional reporting by Larry Celona